📄 qdesigner_actions.cpp
字号:
} // Otherwise load it. QFile f(fileName); if (!f.open(QFile::ReadOnly)) { QMessageBox::warning(core()->topLevel(), tr("Read Error"), tr("Couldn't open file: %1\nReason: %2") .arg(f.fileName()).arg(f.errorString())); return false; } m_openDirectory = QFileInfo(f).absolutePath(); QDesignerFormWindow *formWindow = workbench()->createFormWindow(); if (QDesignerFormWindowInterface *editor = formWindow->editor()) { editor->setFileName(fileName); editor->setContents(&f); Q_ASSERT(editor->mainContainer() != 0); formWindow->updateWindowTitle(fileName); formWindow->resize(editor->mainContainer()->size()); formWindowManager->setActiveFormWindow(editor); } formWindow->show(); addRecentFile(fileName); formWindow->editor()->setDirty(false); return true;}bool QDesignerActions::writeOutForm(QDesignerFormWindowInterface *fw, const QString &saveFile){ Q_ASSERT(fw && !saveFile.isEmpty()); QFile f(saveFile); while (!f.open(QFile::WriteOnly)) { QMessageBox box(tr("Save Form?"), tr("Could not open file: %1" "\nReason: %2" "\nWould you like to retry or change your file?") .arg(f.fileName()).arg(f.errorString()), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, QMessageBox::Cancel | QMessageBox::Escape, fw, Qt::Sheet); box.setButtonText(QMessageBox::Yes, tr("Retry")); box.setButtonText(QMessageBox::No, tr("Select New File")); switch(box.exec()) { case QMessageBox::Yes: break; case QMessageBox::No: { QString fileName = QFileDialog::getSaveFileName(fw, tr("Save form as"), QDir::current().absolutePath(), QLatin1String("*.ui")); if (fileName.isEmpty()) return false; f.setFileName(fileName); fw->setFileName(fileName); break; } case QMessageBox::Cancel: return false; } } QByteArray utf8Array = fw->contents().toUtf8(); while (f.write(utf8Array, utf8Array.size()) != utf8Array.size()) { QMessageBox box(tr("Save Form?"), tr("Could not write file: %1\nReason:%2\nWould you like to retry?") .arg(f.fileName()).arg(f.errorString()), QMessageBox::Warning, QMessageBox::Yes | QMessageBox::Default, QMessageBox::No, 0, fw, Qt::Sheet); box.setButtonText(QMessageBox::Yes, tr("Retry")); box.setButtonText(QMessageBox::No, tr("Don't Retry")); switch(box.exec()) { case QMessageBox::Yes: f.resize(0); break; case QMessageBox::No: return false; } } addRecentFile(saveFile); fw->setDirty(false); fw->parentWidget()->setWindowModified(false); return true;}void QDesignerActions::shutdown(){ // Follow the idea from the Mac, i.e. send the Application a close event // and if it's accepted, quit. QCloseEvent ev; QApplication::sendEvent(qDesigner, &ev); if (ev.isAccepted()) qDesigner->quit();}void QDesignerActions::activeFormWindowChanged(QDesignerFormWindowInterface *formWindow){ bool enable = formWindow != 0; m_saveFormAction->setEnabled(enable); m_saveFormAsAction->setEnabled(enable); m_saveFormAsTemplateAction->setEnabled(enable); m_closeFormAction->setEnabled(enable); m_editWidgetsAction->setEnabled(enable); m_formSettings->setEnabled(enable); m_previewFormAction->setEnabled(enable); m_styleActions->setEnabled(enable);}void QDesignerActions::updateRecentFileActions(){ QDesignerSettings settings; QStringList files = settings.recentFilesList(); int originalSize = files.size(); int numRecentFiles = qMin(files.size(), int(MaxRecentFiles)); QList<QAction *> recentFilesActs = m_recentFilesActions->actions(); for (int i = 0; i < numRecentFiles; ++i) { QFileInfo fi(files[i]); // If the file doesn't exist anymore, just remove it from the list so // people don't get confused. if (!fi.exists()) { files.removeAt(i); --i; numRecentFiles = qMin(files.size(), int(MaxRecentFiles)); continue; } QString text = fi.fileName(); recentFilesActs[i]->setText(text); recentFilesActs[i]->setIconText(files[i]); recentFilesActs[i]->setVisible(true); } for (int j = numRecentFiles; j < MaxRecentFiles; ++j) recentFilesActs[j]->setVisible(false); // If there's been a change, right it back if (originalSize != files.size()) settings.setRecentFilesList(files);}void QDesignerActions::openRecentForm(){ if (QAction *action = qobject_cast<QAction *>(sender())) { if (!readInForm(action->iconText())) updateRecentFileActions(); // File doesn't exist, remove it from settings }}void QDesignerActions::clearRecentFiles(){ QDesignerSettings settings; settings.setRecentFilesList(QStringList()); updateRecentFileActions();}QActionGroup *QDesignerActions::recentFilesActions() const{ return m_recentFilesActions;}void QDesignerActions::addRecentFile(const QString &fileName){ QDesignerSettings settings; QStringList files = settings.recentFilesList(); files.removeAll(fileName); files.prepend(fileName); while (files.size() > MaxRecentFiles) files.removeLast(); settings.setRecentFilesList(files); updateRecentFileActions();}void QDesignerActions::minimizeForm(){ if (QDesignerFormWindowInterface *fw = core()->formWindowManager()->activeFormWindow()) { if (m_workbench->mode() == QDesignerWorkbench::DockedMode) { // Yuck, I need to get to the QWorkspaceChild::showShaded(), but there is no way // to do that legally, so I use the QMetaObject as my guide. QMetaObject::invokeMethod(fw->parentWidget()->parentWidget(), "showShaded"); } else { fw->parentWidget()->showMinimized(); } }}void QDesignerActions::bringAllToFront(){ int i; for (i = 0; i < m_workbench->formWindowCount(); ++i) m_workbench->formWindow(i)->raise(); for (i = 0; i < m_workbench->toolWindowCount(); ++i) m_workbench->toolWindow(i)->raise();}QAction *QDesignerActions::minimizeAction() const{ return m_minimizeAction;}QAction *QDesignerActions::bringAllToFront() const{ return m_bringToFrontAction;}void QDesignerActions::showDesignerHelp(){ showHelp(QLatin1String("designer-manual.html"));}void QDesignerActions::showWhatsNew(){ showHelp(QLatin1String("qt4-designer.html"));}void QDesignerActions::showHelp(const QString &url){ if (!m_assistantClient) m_assistantClient = new QAssistantClient(QLibraryInfo::location(QLibraryInfo::BinariesPath), this); QString filePath = QLibraryInfo::location(QLibraryInfo::DocumentationPath) + QLatin1String("/html/") + url; QString cleanFilePath; int index = filePath.lastIndexOf(QLatin1Char('#')); if (index != -1) cleanFilePath = filePath.left(index); else cleanFilePath = filePath; if (!QFile::exists(cleanFilePath)) { filePath = QLibraryInfo::location(QLibraryInfo::DocumentationPath) + QLatin1String("/html/designer-manual.html"); } m_assistantClient->showPage(filePath);}void QDesignerActions::aboutDesigner(){ VersionDialog mb(core()->topLevel()); mb.setWindowTitle(tr("About Qt Designer")); if (mb.exec()) { OublietteView *oubliette = new OublietteView; oubliette->setAttribute(Qt::WA_DeleteOnClose); oubliette->setMinimumSize(800, 600); oubliette->show(); }}QActionGroup *QDesignerActions::uiMode() const{ return m_uiMode;}QAction *QDesignerActions::editWidgets() const{ return m_editWidgetsAction;}void QDesignerActions::showWidgetSpecificHelp(){ QDesignerFormWindowInterface *fw = core()->formWindowManager()->activeFormWindow(); if (!fw) { showDesignerHelp(); return; } QString className; QString currentPropertyName; currentPropertyName = core()->propertyEditor()->currentPropertyName(); if (!currentPropertyName.isEmpty()) { QDesignerPropertySheetExtension *ps = qt_extension<QDesignerPropertySheetExtension *>(core()->extensionManager(), core()->propertyEditor()->object()); if (!ps) ps = qt_extension<QDesignerPropertySheetExtension *>(core()->extensionManager(), fw->cursor()->selectedWidget(0)); Q_ASSERT(ps); className = ps->propertyGroup(ps->indexOf(currentPropertyName)); } else { QDesignerWidgetDataBaseInterface *db = core()->widgetDataBase(); QDesignerWidgetDataBaseItemInterface *dbi = db->item(db->indexOfObject(fw->cursor()->selectedWidget(0), true)); className = dbi->name(); } // ### generalize using the Widget Data Base if (className == QLatin1String("Line")) className = QLatin1String("QFrame"); else if (className == QLatin1String("Spacer")) className = QLatin1String("QSpacerItem"); else if (className == QLatin1String("QLayoutWidget")) className = QLatin1String("QLayout"); QString url = className.toLower(); // special case url += QLatin1String(".html"); if (!currentPropertyName.isEmpty()) url += QLatin1Char('#') + currentPropertyName; showHelp(url);}QAction *QDesignerActions::widgetHelpAction() const{ return m_widgetHelp;}void QDesignerActions::aboutPlugins(){ PluginDialog dlg(core(), core()->topLevel()); dlg.exec();}void QDesignerActions::showFormSettings(){ QDesignerFormWindowInterface *formWindow = core()->formWindowManager()->activeFormWindow(); QDesignerFormWindow *window = m_workbench->findFormWindow(formWindow); FormWindowSettings dlg(formWindow); if (dlg.exec() && window) { formWindow->setDirty(true); window->updateChanged(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -