void MainWindow::initObject() { QAptActions::self()->setBackend(m_backend); emit backendReady(m_backend); connect(m_backend, SIGNAL(packageChanged()), this, SLOT(setActionsEnabled())); connect(m_backend, SIGNAL(cacheReloadFinished()), this, SLOT(setActionsEnabled())); // Set up GUI loadSettings(); setActionsEnabled(); m_managerWidget->setFocus(); }
ScriptCollectionDialog::ScriptCollectionDialog(ScriptCollectionModel *model, QWidget *parent) : QDialog(parent) , m_ui(new Ui::ScriptCollectionDialog()) , m_model(model) { m_ui->setupUi(this); connect(m_ui->actionNewScript, &QAction::triggered, m_model, &ScriptCollectionModel::onCreateScript); connect(m_ui->actionLoadScript, &QAction::triggered, m_model, &ScriptCollectionModel::onLoad); connect(m_ui->actionRun, &QAction::triggered, this, &ScriptCollectionDialog::onRun); connect(m_ui->actionAbort, &QAction::triggered, this, &ScriptCollectionDialog::onAbort); connect(m_ui->actionSave, &QAction::triggered, this, &ScriptCollectionDialog::onSave); connect(m_ui->tabWidget, &QTabWidget::tabCloseRequested, this, &ScriptCollectionDialog::onTabCloseRequested); connect(m_model, &ScriptCollectionModel::scriptAdded, this, &ScriptCollectionDialog::onScriptAdded); connect(m_model, &ScriptCollectionModel::scriptRemoved, this, &ScriptCollectionDialog::onScriptRemoved); for (IScriptUnit *script : m_model->scripts()) { setActionsEnabled(true); onScriptAdded(script); } QSettings settings; restoreGeometry(settings.value(QString(metaObject()->className()) +"/geometry").toByteArray()); }
void MainWindow::initGUI() { QWidget *centralWidget = new QWidget(this); QVBoxLayout *centralLayout = new QVBoxLayout(centralWidget); centralLayout->setSpacing(0); centralLayout->setMargin(0); m_stack = new QStackedWidget(centralWidget); m_stack->setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding); centralLayout->addWidget(m_stack); setCentralWidget(centralWidget); m_managerWidget = new ManagerWidget(m_stack); connect(this, SIGNAL(backendReady(QApt::Backend*)), m_managerWidget, SLOT(setBackend(QApt::Backend*))); connect(m_managerWidget, SIGNAL(packageChanged()), this, SLOT(setActionsEnabled())); m_mainWidget = new QSplitter(this); m_mainWidget->setOrientation(Qt::Horizontal); connect(m_mainWidget, SIGNAL(splitterMoved(int,int)), this, SLOT(saveSplitterSizes())); m_transWidget = new TransactionWidget(this); m_filterBox = new FilterWidget(m_stack); connect(this, SIGNAL(backendReady(QApt::Backend*)), m_filterBox, SLOT(setBackend(QApt::Backend*))); connect(m_filterBox, SIGNAL(filterByGroup(QString)), m_managerWidget, SLOT(filterByGroup(QString))); connect(m_filterBox, SIGNAL(filterByStatus(QApt::Package::State)), m_managerWidget, SLOT(filterByStatus(QApt::Package::State))); connect(m_filterBox, SIGNAL(filterByOrigin(QString)), m_managerWidget, SLOT(filterByOrigin(QString))); connect(m_filterBox, SIGNAL(filterByArchitecture(QString)), m_managerWidget, SLOT(filterByArchitecture(QString))); m_mainWidget->addWidget(m_filterBox); m_mainWidget->addWidget(m_managerWidget); loadSplitterSizes(); m_stack->addWidget(m_transWidget); m_stack->addWidget(m_mainWidget); m_stack->setCurrentWidget(m_mainWidget); m_backend = new QApt::Backend(this); QApt::FrontendCaps caps = (QApt::FrontendCaps)(QApt::DebconfCap | QApt::MediumPromptCap | QApt::ConfigPromptCap | QApt::UntrustedPromptCap); m_backend->setFrontendCaps(caps); QAptActions* actions = QAptActions::self(); actions->setMainWindow(this); connect(actions, SIGNAL(changesReverted()), this, SLOT(revertChanges())); setupActions(); m_statusWidget = new StatusWidget(centralWidget); connect(this, SIGNAL(backendReady(QApt::Backend*)), m_statusWidget, SLOT(setBackend(QApt::Backend*))); centralLayout->addWidget(m_statusWidget); }
void ScriptCollectionDialog::onScriptRemoved(IScriptUnit *script) { int index = indexByScript(script); ScriptUnitView *view = qobject_cast<ScriptUnitView *>(m_ui->tabWidget->widget(index)); m_ui->tabWidget->removeTab(index); delete view; if (m_ui->tabWidget->count() == 0) setActionsEnabled(false); }
void MainWindow::checkForUpdates() { setActionsEnabled(false); m_managerWidget->setEnabled(false); m_stack->setCurrentWidget(m_transWidget); m_trans = m_backend->updateCache(); setupTransaction(m_trans); m_trans->run(); }
void MainWindow::startInit(){ setActionsEnabled(false); ui->delayspinBox->setEnabled(false); ui->sendmsgBtn->setEnabled(false); ui->sendMsgLineEdit->setEnabled(false); ui->obocheckBox->setEnabled(false); ui->actionAdd->setEnabled(true); //初始化连续发送计时器计时间隔 obotimerdly = OBO_TIMER_INTERVAL; //设置连续发送计时器 obotimer = new QTimer(this); connect(obotimer, SIGNAL(timeout()), this, SLOT(sendMsg())); ui->Red_horizontalSlider->setMinimum(0);//Slider的最小值 ui->Green_horizontalSlider->setMinimum(0); ui->Blue_horizontalSlider->setMinimum(0); ui->Red_horizontalSlider->setMaximum(255);//Slider的最大值 ui->Green_horizontalSlider->setMaximum(255); ui->Blue_horizontalSlider->setMaximum(255); ui->Red_horizontalSlider->setValue(Red.toInt());//Slider的初始化值 ui->Green_horizontalSlider->setValue(Green.toInt()); ui->Blue_horizontalSlider->setValue(Blue.toInt()); ui->Red_horizontalSlider->setPageStep(1);//Slider的每次变化为1 ui->Green_horizontalSlider->setPageStep(1); ui->Blue_horizontalSlider->setPageStep(1); ui->obocheckBox->setVisible(false); ui->obocheckBox->setEnabled(false); ui->delayspinBox->setVisible(false); ui->delayspinBox->setEnabled(false); ui->label_6->setVisible(false); ui->Human_lineEdit->setText("未检测到人靠近"); ui->Fire_lineEdit->setText("未检测到火焰"); ui->Sound_lineEdit->setText("未检测到声音"); ui->Temp_lcdNumber->display("30"); ui->Humidity_lcdNumber->display("30"); ui->Lux_lcdNumber->display("00000"); ui->MQ2_lcdNumber->display("00000"); ui->MQ7_lcdNumber->display("00000"); ui->Red_lcdNumber->display("128"); ui->Blue_lcdNumber->display("128"); ui->Green_lcdNumber->display("128"); ui->Red_horizontalSlider->setValue(128); ui->Blue_horizontalSlider->setValue(128); ui->Green_horizontalSlider->setValue(128); }
void MainWindow::startCommit() { setActionsEnabled(false); m_managerWidget->setEnabled(false); QApplication::setOverrideCursor(Qt::WaitCursor); m_stack->setCurrentWidget(m_transWidget); m_trans = m_backend->commitChanges(); setupTransaction(m_trans); m_trans->run(); }
void MainWindow::errorOccurred(QApt::ErrorCode error) { switch(error) { case QApt::AuthError: case QApt::LockError: m_managerWidget->setEnabled(true); QApplication::restoreOverrideCursor(); returnFromPreview(); setActionsEnabled(); break; default: break; } }
void MainWindow::setupActions() { QAction *quitAction = KStandardAction::quit(QCoreApplication::instance(), SLOT(quit()), actionCollection()); actionCollection()->addAction("file_quit", quitAction); QAction *focusSearchAction = KStandardAction::find(this, SLOT(setFocusSearchEdit()), actionCollection()); actionCollection()->addAction("find", focusSearchAction); m_safeUpgradeAction = actionCollection()->addAction("safeupgrade"); m_safeUpgradeAction->setIcon(QIcon::fromTheme("go-up")); m_safeUpgradeAction->setText(i18nc("@action Marks upgradeable packages for upgrade", "Cautious Upgrade")); connect(m_safeUpgradeAction, SIGNAL(triggered()), this, SLOT(markUpgrade())); m_distUpgradeAction = actionCollection()->addAction("fullupgrade"); m_distUpgradeAction->setIcon(QIcon::fromTheme("go-top")); m_distUpgradeAction->setText(i18nc("@action Marks upgradeable packages, including ones that install/remove new things", "Full Upgrade")); connect(m_distUpgradeAction, SIGNAL(triggered()), this, SLOT(markDistUpgrade())); m_autoRemoveAction = actionCollection()->addAction("autoremove"); m_autoRemoveAction->setIcon(QIcon::fromTheme("trash-empty")); m_autoRemoveAction->setText(i18nc("@action Marks packages no longer needed for removal", "Remove Unnecessary Packages")); connect(m_autoRemoveAction, SIGNAL(triggered()), this, SLOT(markAutoRemove())); m_previewAction = actionCollection()->addAction("preview"); m_previewAction->setIcon(QIcon::fromTheme("document-preview-archive")); m_previewAction->setText(i18nc("@action Takes the user to the preview page", "Preview Changes")); connect(m_previewAction, SIGNAL(triggered()), this, SLOT(previewChanges())); m_applyAction = actionCollection()->addAction("apply"); m_applyAction->setIcon(QIcon::fromTheme("dialog-ok-apply")); m_applyAction->setText(i18nc("@action Applys the changes a user has made", "Apply Changes")); connect(m_applyAction, SIGNAL(triggered()), this, SLOT(startCommit())); QAction* updateAction = actionCollection()->addAction("update"); updateAction->setIcon(QIcon::fromTheme("system-software-update")); updateAction->setText(i18nc("@action Checks the Internet for updates", "Check for Updates")); actionCollection()->setDefaultShortcut(updateAction, QKeySequence(Qt::CTRL + Qt::Key_R)); connect(updateAction, SIGNAL(triggered()), SLOT(checkForUpdates())); updateAction->setEnabled(QAptActions::self()->isConnected()); connect(QAptActions::self(), SIGNAL(shouldConnect(bool)), updateAction, SLOT(setEnabled(bool))); KStandardAction::preferences(this, SLOT(editSettings()), actionCollection()); setActionsEnabled(false); setupGUI(StandardWindowOption(KXmlGuiWindow::Default & ~KXmlGuiWindow::StatusBar)); }
//打开串口 void MainWindow::on_actionOpen_triggered() { QString portName = ui->portNameComboBox->currentText(); //获取串口名 myCom = new Win_QextSerialPort(portName, QextSerialBase::Polling); //这里QextSerialBase::QueryMode应该使用QextSerialBase::Polling if(myCom->open(QIODevice::ReadWrite)){ QMessageBox::information(this, tr("打开成功"), tr("已成功打开串口 ") + portName, QMessageBox::Ok); }else{ QMessageBox::critical(this, tr("打开失败"), tr("未能打开串口 ") + portName + tr("\n该串口设备不存在或已被占用"), QMessageBox::Ok); return; } //设置波特率 myCom->setBaudRate((BaudRateType)ui->baudRateComboBox->currentIndex()); //设置数据位 myCom->setDataBits((DataBitsType)ui->dataBitsComboBox->currentIndex()); //设置校验 myCom->setParity((ParityType)ui->parityComboBox->currentIndex()); //设置停止位 myCom->setStopBits((StopBitsType)ui->stopBitsComboBox->currentIndex()); //界面控制 ui->sendmsgBtn->setEnabled(true); setComboBoxEnabled(false); ui->sendMsgLineEdit->setEnabled(true); ui->actionOpen->setEnabled(false); ui->sendMsgLineEdit->setFocus(); ui->obocheckBox->setEnabled(true); ui->actionAdd->setEnabled(false); setActionsEnabled(true); //开启读取定时器 timer->start(timerdly); //设置数据流控制 myCom->setFlowControl(FLOW_OFF); //设置延时 myCom->setTimeout(TIME_OUT); ui->statusBar->showMessage(tr("打开串口成功")); }
void MainWindow::transactionStatusChanged(QApt::TransactionStatus status) { // FIXME: better support for transactions that do/don't need reloads switch (status) { case QApt::RunningStatus: case QApt::WaitingStatus: QApplication::restoreOverrideCursor(); m_stack->setCurrentWidget(m_transWidget); break; case QApt::FinishedStatus: reload(); setActionsEnabled(); m_trans->deleteLater(); m_trans = nullptr; break; default: break; } }
//关闭串口 void MainWindow::on_actionClose_triggered() { myCom->close(); delete myCom; myCom = NULL; ui->sendmsgBtn->setEnabled(false); setComboBoxEnabled(true); ui->actionOpen->setEnabled(true); ui->sendMsgLineEdit->setEnabled(false); ui->obocheckBox->setEnabled(false); ui->actionAdd->setEnabled(true); setActionsEnabled(false); ui->actionWriteToFile->setChecked(false); ui->statusBar->showMessage(tr("串口已经关闭")); }
void MainWindow::startInit(){ setActionsEnabled(false); ui->delayspinBox->setEnabled(false); ui->sendmsgBtn->setEnabled(false); ui->sendMsgLineEdit->setEnabled(false); ui->obocheckBox->setEnabled(false); ui->actionAdd->setEnabled(true); //初始化连续发送计时器计时间隔 obotimerdly = OBO_TIMER_INTERVAL; //设置连续发送计时器 obotimer = new QTimer(this); connect(obotimer, SIGNAL(timeout()), this, SLOT(sendMsg())); ui->Lux_lcdNumber->display("128"); }
void ScriptCollectionDialog::onScriptAdded(IScriptUnit *script) { ScriptUnitView *scriptView = new ScriptUnitView(script, new CodeHighlighter(ColorTheme::getDefault(), this), this); bool savable = !script->fileName().isEmpty(); int index = m_ui->tabWidget->addTab(scriptView, savable ? script->fileName() : "Untitled"); m_ui->tabWidget->setCurrentIndex(index); setActionsEnabled(true); bool modified = scriptView->data()->script()->isModified(); if (modified || !savable) // script in memory always marked as unsaved setModifiedMark(index); connect(scriptView->data()->script(), &QTextDocument::modificationChanged, this, &ScriptCollectionDialog::onCurrentScriptModificationChanged); connect(scriptView->data(), &IScriptUnit::fileNameChanged, this, &ScriptCollectionDialog::onScriptFileNameChanged); }
void MainWindow::reload() { m_reloading = true; returnFromPreview(); m_stack->setCurrentWidget(m_mainWidget); // Reload the QApt Backend m_managerWidget->reload(); // Reload other widgets if (m_reviewWidget) { m_reviewWidget->reload(); } m_filterBox->reload(); QAptActions::self()->setOriginalState(m_backend->currentCacheState()); m_statusWidget->updateStatus(); setActionsEnabled(); m_managerWidget->setEnabled(true); m_reloading = false; }
//打开串口 void MainWindow::on_actionOpen_triggered() { QString portName = ui->portNameComboBox->currentText(); //获取串口名 #ifdef Q_OS_LINUX myCom = new QextSerialPort("/dev/" + portName); #elif defined (Q_OS_WIN) myCom = new QextSerialPort(portName); #endif connect(myCom, SIGNAL(readyRead()), this, SLOT(readMyCom())); //设置波特率 myCom->setBaudRate((BaudRateType)ui->baudRateComboBox->currentText().toInt()); //设置数据位 myCom->setDataBits((DataBitsType)ui->dataBitsComboBox->currentText().toInt()); //设置校验 switch(ui->parityComboBox->currentIndex()){ case 0: myCom->setParity(PAR_NONE); break; case 1: myCom->setParity(PAR_ODD); break; case 2: myCom->setParity(PAR_EVEN); break; default: myCom->setParity(PAR_NONE); qDebug("set to default : PAR_NONE"); break; } //设置停止位 switch(ui->stopBitsComboBox->currentIndex()){ case 0: myCom->setStopBits(STOP_1); break; case 1: #ifdef Q_OS_WIN myCom->setStopBits(STOP_1_5); #endif break; case 2: myCom->setStopBits(STOP_2); break; default: myCom->setStopBits(STOP_1); qDebug("set to default : STOP_1"); break; } //设置数据流控制 myCom->setFlowControl(FLOW_OFF); //设置延时 myCom->setTimeout(TIME_OUT); if(myCom->open(QIODevice::ReadWrite)){ QMessageBox::information(this, tr("打开成功"), tr("已成功打开串口") + portName, QMessageBox::Ok); //界面控制 ui->sendmsgBtn->setEnabled(true); setComboBoxEnabled(false); ui->sendMsgLineEdit->setEnabled(true); ui->actionOpen->setEnabled(false); ui->sendMsgLineEdit->setFocus(); ui->obocheckBox->setEnabled(true); ui->actionAdd->setEnabled(false); setActionsEnabled(true); }else{ QMessageBox::critical(this, tr("打开失败"), tr("未能打开串口 ") + portName + tr("\n该串口设备不存在或已被占用"), QMessageBox::Ok); return; } ui->statusBar->showMessage(tr("打开串口成功")); }
// this should be pushed from listview, not pulled void KEBApp::updateActions() { resetActions(); setActionsEnabled(ListView::self()->getSelectionAbilities()); }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), quitDialog(0), saveChanges(false), newJobFileName(""), newJobDestinationDirectory("") { m_has_error_happend = false; QMetaObject::invokeMethod(this, "loadSettings", Qt::QueuedConnection); setWindowIcon(QIcon(":/ui/icons/motocool.jpg")); // Initiallize headers QStringList headers; headers << tr("Name") << tr("Downloaded/Total") << tr("Progress") << tr("Speed") << tr("Status") << tr("Remaining time"); // Main job list jobView = new JobView(this); jobView->setHeaderLabels(headers); jobView->setSelectionBehavior(QAbstractItemView::SelectRows); jobView->setAlternatingRowColors(true); jobView->setRootIsDecorated(false); setCentralWidget(jobView); // Set header resize modes and initial section sizes QFontMetrics fm = fontMetrics(); QHeaderView *header = jobView->header(); header->resizeSection(0, fm.width("typical-name-length-for-a-download-task")); header->resizeSection(1, fm.width(headers.at(1) + "100MB/999MB")); header->resizeSection(2, fm.width(headers.at(2) + "100%")); header->resizeSection(3, qMax(fm.width(headers.at(3) + " "), fm.width(" 1023.0 KB/s"))); header->resizeSection(4, qMax(fm.width(headers.at(4) + " "), fm.width(tr("Downloading ") + " "))); header->resizeSection(5, qMax(fm.width(headers.at(5) + " "), fm.width(tr("--:--") + " "))); // Create common actions QAction *newJobAction = new QAction(QIcon(":/ui/icons/bottom.png"), tr("Add &new job"), this); pauseJobAction = new QAction(QIcon(":/ui/icons/player_pause.png"), tr("&Pause job"), this); removeJobAction = new QAction(QIcon(":/ui/icons/player_stop.png"), tr("&Remove job"), this); openDirAction = new QAction(QIcon(":/ui/icons/folder.png"), tr("Open file &directory"), this); // File menu QMenu *fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(newJobAction); fileMenu->addAction(pauseJobAction); fileMenu->addAction(removeJobAction); fileMenu->addAction(openDirAction); fileMenu->addSeparator(); fileMenu->addAction(QIcon(":/ui/icons/exit.png"), tr("E&xit"), this, SLOT(close())); // Help Menu QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(tr("&About"), this, SLOT(about())); // Top toolbar QToolBar *topBar = new QToolBar(tr("Tools")); addToolBar(Qt::TopToolBarArea, topBar); topBar->setMovable(false); topBar->addAction(newJobAction); topBar->addAction(pauseJobAction); topBar->addAction(removeJobAction); topBar->addAction(openDirAction); pauseJobAction->setEnabled(false); removeJobAction->setEnabled(false); openDirAction->setEnabled(false); // Set up connections connect(jobView, SIGNAL(itemSelectionChanged()), this, SLOT(setActionsEnabled())); connect(newJobAction, SIGNAL(triggered()), this, SLOT(addJob())); connect(pauseJobAction, SIGNAL(triggered()), this, SLOT(pauseJob())); connect(removeJobAction, SIGNAL(triggered()), this, SLOT(removeJob())); connect(openDirAction, SIGNAL(triggered()), this, SLOT(openDir())); }