File indexing completed on 2022-11-23 10:29:25

0001 #define QT3_SUPPORT
0002 #define QT3_SUPPORT_WARNINGS
0003 
0004 #include <QWidget>
0005 #include <QString>
0006 #include <QMessageBox>
0007 #include <QTextEdit>
0008 #include <QtCore>
0009 #include <QPixmap>
0010 #include <QCursor>
0011 
0012 #include <stdlib.h>
0013 
0014 #include "kstatusbar.h"
0015 #include <QApplication>
0016 #include <kglobal.h>
0017 #include <kmainwindow.h>
0018 #include "kstatusbartest.h"
0019 
0020 testWindow::testWindow(QWidget *)
0021     : KXmlGuiWindow(nullptr)
0022 {
0023     // Setup Menus
0024     menuBar = new KMenuBar(this);
0025     fileMenu = new QMenu;
0026     menuBar->addAction("&File");
0027     QAction *action = fileMenu->addAction("&Exit");
0028     action->setShortcut(Qt::ALT | Qt::Key_Q);
0029 
0030     connect(action, SIGNAL(triggered()), qApp, SLOT(quit()));
0031 
0032     statusbar = new KStatusBar(this);
0033     setStatusBar(statusbar);
0034     statusbar->insertItem("Zoom: XXXX", 0);
0035     statusbar->insertItem("XXX", 1);
0036     statusbar->insertItem("Line: XXXXX", 2);
0037 
0038     statusbar->changeItem("Zoom: 100%", 0);
0039     statusbar->changeItem("INS", 1);
0040     insert = true;
0041     statusbar->changeItem("Line: 13567", 2);
0042 
0043     connect(statusbar, SIGNAL(pressed(int)), this, SLOT(slotPress(int)));
0044     connect(statusbar, SIGNAL(released(int)), this, SLOT(slotClick(int)));
0045 
0046     widget = new QTextEdit(this);
0047 
0048     setCentralWidget(widget);
0049 
0050     setCaption(KGlobal::caption());
0051 
0052     smenu = new QMenu;
0053 
0054     smenu->addAction("50%");
0055     smenu->addAction("75%");
0056     smenu->addAction("100%");
0057     smenu->addAction("150%");
0058     smenu->addAction("200%");
0059     smenu->addAction("400%");
0060     smenu->addAction("oo%");
0061 
0062     connect(smenu, SIGNAL(triggered(QAction*)), this, SLOT(slotMenu(QAction*)));
0063 }
0064 
0065 void testWindow::slotClick(int id)
0066 {
0067     switch (id) {
0068     case 0:
0069         break;
0070 
0071     case 1:
0072         if (insert == true) {
0073             insert = false;
0074             statusbar->changeItem("OVR", 1);
0075         } else {
0076             insert = true;
0077             statusbar->changeItem("INS", 1);
0078         }
0079         break;
0080 
0081     case 2:
0082         QMessageBox::information(nullptr, "Go to line", "Enter line number:", "where?");
0083         statusbar->changeItem("16543", 2);
0084         break;
0085     }
0086 }
0087 
0088 void testWindow::slotPress(int id)
0089 {
0090     if (id == 0) {
0091         smenu->popup(QCursor::pos());    // This popup should understand keys up and down
0092     }
0093 }
0094 
0095 void testWindow::slotMenu(QAction *action)
0096 {
0097     QString s = "Zoom: ";
0098     s.append(action->text());
0099     statusbar->changeItem(s, 0);
0100 }
0101 
0102 testWindow::~testWindow()
0103 {
0104     // I would delete toolbars here, but there are none
0105     delete statusbar;
0106 }
0107 
0108 int main(int argc, char *argv[])
0109 {
0110     QApplication::setApplicationName("test");
0111     QApplication *myApp = new QApplication(argc, argv);
0112     testWindow *test = new testWindow;
0113 
0114     test->show();
0115     test->resize(test->width(), test->height()); // I really really really dunno why it doesn't show
0116     int ret = myApp->exec();
0117 
0118     delete test;
0119 
0120     return ret;
0121 }
0122