KbManager::KbManager(QObject *parent) : QObject(parent){ // Set up the timers _eventTimer = new QTimer(this); _eventTimer->setTimerType(Qt::PreciseTimer); _scanTimer = new QTimer(this); _scanTimer->start(1000); connect(_scanTimer, SIGNAL(timeout()), this, SLOT(scanKeyboards())); // Scan for keyboards immediately so they show up as soon as the GUI appears. QTimer::singleShot(0,this,SLOT(scanKeyboards())); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); trayIconMenu = new QMenu(this); restoreAction = new QAction(tr("Restore"), this); closeAction = new QAction(tr("Exit"), this); trayIconMenu->addAction(restoreAction); trayIconMenu->addAction(closeAction); trayIcon = new QSystemTrayIcon(QIcon(":/img/ckb-logo.png"), this); trayIcon->setContextMenu(trayIconMenu); trayIcon->show(); ui->tabWidget->addTab(noKbWidget = new QWidget(this), noKbMsg); connect(ui->actionExit, SIGNAL(triggered()), qApp, SLOT(quit())); connect(ui->actionAbout, SIGNAL(triggered()), this, SLOT(about())); connect(closeAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(restoreAction, SIGNAL(triggered()), this, SLOT(show())); eventTimer = new QTimer(this); connect(eventTimer, SIGNAL(timeout()), this, SLOT(timerTick())); eventTimer->start(16); scanKeyboards(); }
void MainWindow::timerTick(){ // Check if another instance requested this in the foreground if(appShare.lock()){ void* data = appShare.data(); if((QString)QByteArray((const char*)data) == "Open") show(); // Remove the request *(char*)data = 0; appShare.unlock(); } scanKeyboards(); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); mainWindow = this; trayIconMenu = new QMenu(this); restoreAction = new QAction(tr("Restore"), this); closeAction = new QAction(tr("Quit ckb"), this); trayIconMenu->addAction(restoreAction); trayIconMenu->addAction(closeAction); trayIcon = new QSystemTrayIcon(QIcon(":/img/ckb-logo.png"), this); trayIcon->setContextMenu(trayIconMenu); if(!CkbSettings::get("Program/SuppressTrayIcon").toBool()) trayIcon->show(); #ifdef Q_OS_MACX // Make a custom "Close" menu action for OSX, as the default one brings up the "still running" popup unnecessarily QMenuBar* menuBar = new QMenuBar(this); setMenuBar(menuBar); this->menuBar()->addMenu("ckb")->addAction(closeAction); #else // On linux, add a handler for Ctrl+Q new QShortcut(QKeySequence("Ctrl+Q"), this, SLOT(quitApp())); #endif connect(ui->actionExit, SIGNAL(triggered()), this, SLOT(quitApp())); connect(closeAction, SIGNAL(triggered()), this, SLOT(quitApp())); connect(restoreAction, SIGNAL(triggered()), this, SLOT(showWindow())); connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(iconClicked(QSystemTrayIcon::ActivationReason))); connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(cleanup())); eventTimer = new QTimer(this); eventTimer->setTimerType(Qt::PreciseTimer); connect(eventTimer, SIGNAL(timeout()), this, SLOT(timerTick())); eventTimer->start(1000 / 60); QCoreApplication::setOrganizationName("ckb"); ui->tabWidget->addTab(settingsWidget = new SettingsWidget(this), configLabel); settingsWidget->setVersion("ckb " CKB_VERSION_STR); ckbGuiVersion = PARSE_CKB_VERSION(CKB_VERSION_STR); scanKeyboards(); }