bool DesignerApp::initApplication(QString cmdLine) { QLocale::setDefault(QLocale(QLocale::English)); QTextCodec::setCodecForTr(QTextCodec::codecForLocale()); QPixmap pixmap(":/designer/splash.png"); QSplashScreen *splash = new QSplashScreen(pixmap); splash->show(); splash->showMessage(tr("Loading...")); processEvents(); writeConfigValue("", "apppath", QtSingleApplication::applicationFilePath()); dbIgame = QSqlDatabase::addDatabase("QMYSQL","igame"); dbIgame.setDatabaseName("MoDeL"); dbIgame.setHostName("localhost"); dbIgame.setUserName("root"); dbIgame.setPassword("lovewin"); dbIgame.open(); DesignerViewMgr::initializeIfNotYet(); DesignerDocMgr::initializeIfNotYet(); DesignerModelMgr::initializeIfNotYet(); DesignerExtensionMgr::initializeIfNotYet(); DesignerMainWnd* mainWnd = DesignerMainWnd::globalCreateNewMainWnd(); setActivationWindow(mainWnd); QObject::connect(this, SIGNAL(messageReceived(const QString&)), mainWnd, SLOT(instanceMessageReceived(const QString&))); splash->setWindowFlags(Qt::WindowStaysOnTopHint); splash->setParent(mainWnd); splash->show(); QTimer::singleShot(1500, splash, SLOT(close())); if(cmdLine!="/new") mainWnd->instanceMessageReceived(cmdLine); while(splash->isVisible()) { processEvents(); } return true; }
int main(int argc, char *argv[]) { QtilitiesApplication a(argc, argv); QtilitiesApplication::setOrganizationName("Jaco Naude"); QtilitiesApplication::setOrganizationDomain("Qtilities"); QtilitiesApplication::setApplicationName("Main Window Example"); QtilitiesApplication::setApplicationVersion(QtilitiesApplication::qtilitiesVersionString()); // Create a QtilitiesMainWindow to show our different modes: QtilitiesMainWindow exampleMainWindow(QtilitiesMainWindow::ModesBottom); QtilitiesApplication::setMainWindow(&exampleMainWindow); // Create the configuration widget: ConfigurationWidget config_widget; config_widget.setCategorizedTabDisplay(true); QtilitiesApplication::setConfigWidget(&config_widget); // Initialize the logger: Log->setLoggerSessionConfigPath(QtilitiesApplication::applicationSessionPath()); LOG_INITIALIZE(); Log->setIsQtMessageHandler(false); // Add a formatting hint to the RichText formatting engine. AbstractFormattingEngine* rich_text_engine = Log->formattingEngineReference(qti_def_FORMATTING_ENGINE_RICH_TEXT); if (rich_text_engine) { QRegExp reg_exp_success_color = QRegExp(QObject::tr("Successfully") + "*",Qt::CaseInsensitive,QRegExp::Wildcard); CustomFormattingHint success_message_hint(reg_exp_success_color,"green",Logger::Info); rich_text_engine->addColorFormattingHint(success_message_hint); } // Speed up application launching a bit... ACTION_MANAGER->commandObserver()->startProcessingCycle(); ACTION_MANAGER->actionContainerObserver()->startProcessingCycle(); OBJECT_MANAGER->objectPool()->startProcessingCycle(); // We show a splash screen in this example: #ifdef QT_NO_DEBUG QPixmap pixmap(QTILITIES_LOGO_BT_300x300); QSplashScreen *splash = new QSplashScreen(pixmap); splash->setWindowFlags(Qt::SplashScreen | Qt::WindowStaysOnTopHint); splash->show(); QObject::connect(EXTENSION_SYSTEM,SIGNAL(newProgressMessage(QString)),splash,SLOT(showMessage(QString))); a.processEvents(); #endif // Initialize the clipboard manager: CLIPBOARD_MANAGER->initialize(); // Create menu related things. bool existed; ActionContainer* menu_bar = ACTION_MANAGER->createMenuBar(qti_action_MENUBAR_STANDARD,existed); exampleMainWindow.setMenuBar(menu_bar->menuBar()); ActionContainer* file_menu = ACTION_MANAGER->createMenu(qti_action_FILE,existed); ActionContainer* edit_menu = ACTION_MANAGER->createMenu(qti_action_EDIT,existed); ActionContainer* view_menu = ACTION_MANAGER->createMenu(qti_action_VIEW,existed); ActionContainer* about_menu = ACTION_MANAGER->createMenu(qti_action_ABOUT,existed); menu_bar->addMenu(file_menu); menu_bar->addMenu(edit_menu); menu_bar->addMenu(view_menu); menu_bar->addMenu(about_menu); // Get the standard context. QList<int> std_context; std_context.push_front(CONTEXT_MANAGER->contextID(qti_def_CONTEXT_STANDARD)); // Register action place holders for this application. This allows control of your menu structure. // File Menu Command* command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_FILE_SETTINGS,QObject::tr("Settings"),QKeySequence(),std_context); QObject::connect(command->action(),SIGNAL(triggered()),&config_widget,SLOT(show())); file_menu->addAction(command); // Edit Menu command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_UNDO,QObject::tr("Undo"),QKeySequence(QKeySequence::Undo)); command->setCategory(QtilitiesCategory("Editing")); edit_menu->addAction(command); command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_REDO,QObject::tr("Redo"),QKeySequence(QKeySequence::Redo)); command->setCategory(QtilitiesCategory("Editing")); edit_menu->addAction(command); edit_menu->addSeperator(); command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_COPY,QObject::tr("Copy"),QKeySequence(QKeySequence::Copy)); command->setCategory(QtilitiesCategory("Editing")); edit_menu->addAction(command); command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_CUT,QObject::tr("Cut"),QKeySequence(QKeySequence::Cut)); command->setCategory(QtilitiesCategory("Editing")); edit_menu->addAction(command); command = ACTION_MANAGER->command(qti_action_EDIT_PASTE); command->setCategory(QtilitiesCategory("Editing")); edit_menu->addAction(command); edit_menu->addSeperator(); command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_SELECT_ALL,QObject::tr("Select All"),QKeySequence(QKeySequence::SelectAll)); command->setCategory(QtilitiesCategory("Editing")); edit_menu->addAction(command); command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_CLEAR,QObject::tr("Clear")); command->setCategory(QtilitiesCategory("Editing")); edit_menu->addAction(command); edit_menu->addSeperator(); command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_EDIT_FIND,QObject::tr("Find"),QKeySequence(QKeySequence::Find)); edit_menu->addAction(command); // Add the code editor config widget: CodeEditorWidgetConfig code_editor_config; OBJECT_MANAGER->registerObject(&code_editor_config,QtilitiesCategory("GUI::Configuration Pages (IConfigPage)","::")); // Create the Example before plugin loading since it registers a project items: ExampleMode* example_mode = new ExampleMode; file_menu->addSeperator(); command = ACTION_MANAGER->registerActionPlaceHolder("File.ToggleModeIcon",QObject::tr("Toggle Mode Icon"),QKeySequence(),std_context); QObject::connect(command->action(),SIGNAL(triggered()),example_mode,SLOT(toggleModeIcon())); file_menu->addAction(command); OBJECT_MANAGER->registerObject(example_mode); file_menu->addSeperator(); command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_FILE_EXIT,QObject::tr("Exit"),QKeySequence(QKeySequence::Close),std_context); QObject::connect(command->action(),SIGNAL(triggered()),QCoreApplication::instance(),SLOT(quit())); file_menu->addAction(command); // About Menu command = ACTION_MANAGER->registerActionPlaceHolder(qti_action_ABOUT_QTILITIES,QObject::tr("About Qtilities"),QKeySequence(),std_context); QObject::connect(command->action(),SIGNAL(triggered()),QtilitiesApplication::instance(),SLOT(aboutQtilities())); about_menu->addAction(command); command = ACTION_MANAGER->registerActionPlaceHolder("General.AboutQt","About Qt",QKeySequence(),std_context); about_menu->addAction(command); QObject::connect(command->action(),SIGNAL(triggered()),QApplication::instance(),SLOT(aboutQt())); // Load plugins using the extension system: Log->toggleQtMsgEngine(true); EXTENSION_SYSTEM->enablePluginActivityControl(); EXTENSION_SYSTEM->addPluginPath("../../plugins/"); EXTENSION_SYSTEM->initialize(); Log->toggleQtMsgEngine(false); #ifdef QT_NO_DEBUG splash->clearMessage(); #endif // Create the example file system side widget and add it to the global object pool QList<int> modes; modes << MODE_EXAMPLE_ID; SideViewerWidgetFactory* file_system_side_widget_helper = new SideViewerWidgetFactory(&SideWidgetFileSystem::factory,"File System",modes,modes); OBJECT_MANAGER->registerObject(file_system_side_widget_helper,QtilitiesCategory("GUI::Side Viewer Widgets (ISideViewerWidget)","::")); QObject::connect(file_system_side_widget_helper,SIGNAL(newWidgetCreated(QWidget*,QString)),example_mode,SLOT(handleNewFileSystemWidget(QWidget*))); SideViewerWidgetFactory* object_scope_side_widget_helper = new SideViewerWidgetFactory(&ObjectScopeWidget::factory,"Object Scope",modes,modes); OBJECT_MANAGER->registerObject(object_scope_side_widget_helper,QtilitiesCategory("GUI::Side Viewer Widgets (ISideViewerWidget)","::")); #ifdef QTILITIES_PROPERTY_BROWSER SideViewerWidgetFactory* property_editor_side_widget_helper = new SideViewerWidgetFactory(&ObjectPropertyBrowser::factory,"Property Browser",modes,modes); OBJECT_MANAGER->registerObject(property_editor_side_widget_helper,QtilitiesCategory("GUI::Side Viewer Widgets (ISideViewerWidget)","::")); #endif exampleMainWindow.modeManager()->initialize(); // Register command editor config page. OBJECT_MANAGER->registerObject(ACTION_MANAGER->commandEditor(),QtilitiesCategory("GUI::Configuration Pages (IConfigPage)","::")); // Register extension system config page. OBJECT_MANAGER->registerObject(EXTENSION_SYSTEM->configWidget(),QtilitiesCategory("GUI::Configuration Pages (IConfigPage)","::")); // Report on the number of config pages found. QList<QObject*> registered_config_pages = OBJECT_MANAGER->registeredInterfaces("IConfigPage"); LOG_INFO(QString("%1 configuration page(s) found in set of loaded plugins.").arg(registered_config_pages.count())); config_widget.initialize(registered_config_pages); // Report on the number of side widgets found. QList<QObject*> registered_side_widgets = OBJECT_MANAGER->registeredInterfaces("ISideViewerWidget"); LOG_INFO(QString("%1 side viewer widget(s) found in set of loaded plugins.").arg(registered_side_widgets.count())); // Load the previous session's keyboard mapping file. QString shortcut_mapping_file = QString("%1/%2").arg(QtilitiesApplication::applicationSessionPath()).arg(qti_def_PATH_SHORTCUTS_FILE); ACTION_MANAGER->loadShortcutMapping(shortcut_mapping_file); // Show the main window: exampleMainWindow.readSettings(); exampleMainWindow.show(); #ifdef QT_NO_DEBUG splash->close(); #endif LOG_INFO("< > < >"); // Initialize the project manager: // PROJECT_MANAGER->setAllowedProjectTypes(IExportable::XML); PROJECT_MANAGER_INITIALIZE(); ACTION_MANAGER->commandObserver()->endProcessingCycle(false); ACTION_MANAGER->actionContainerObserver()->endProcessingCycle(false); OBJECT_MANAGER->objectPool()->endProcessingCycle(false); #ifndef QTILITIES_NO_HELP HELP_MANAGER->initialize(); #endif int result = a.exec(); exampleMainWindow.writeSettings(); // Finalize the project manager: PROJECT_MANAGER_FINALIZE(); // Save the current keyboard mapping for the next session. ACTION_MANAGER->saveShortcutMapping(shortcut_mapping_file); LOG_FINALIZE(); return result; }
DianVoteControl::DianVoteControl(QWidget *parent) : QWidget(parent), ui(new Ui::DianVoteControl), drawer(NULL), hidControl(NULL), stopWatch(NULL), splash(NULL), voteMode(SINGLE_VOTE), curState(STOP) { QDir dir; dir.setCurrent(QCoreApplication::applicationDirPath()); windowIcon = new QIcon(dir.absoluteFilePath("res/images/app-icon.png")); this->setWindowIcon(*windowIcon); // show splash. QPixmap pixmap(dir.absoluteFilePath("res/images/logo.png")); QSplashScreen *splash = new QSplashScreen(pixmap); splash->setWindowIcon(*windowIcon); splash->setWindowFlags(Qt::WindowStaysOnTopHint); splash->setMask(pixmap.mask()); splash->show(); ui->setupUi(this); pbStart = new QPushButton(this); pbStart->setObjectName(tr("pbStart")); ui->buttonLayout->addWidget(pbStart, 0, 0); pbAuto = new QPushButton(this); pbAuto->setObjectName(tr("pbAuto")); ui->buttonLayout->addWidget(pbAuto, 0, 1); pbPause = new QPushButton(this); pbPause->setObjectName(tr("pbPause")); ui->buttonLayout->addWidget(pbPause, 0, 0); pbPause->hide(); pbStop = new QPushButton(this); pbStop->setObjectName(tr("pbStop")); ui->buttonLayout->addWidget(pbStop, 0, 1); pbStop->hide(); pbResult = new QPushButton(this); pbResult->setObjectName(tr("pbResult")); ui->buttonLayout->addWidget(pbResult, 0, 2); pbOption = new QToolButton(this); pbOption->setObjectName(tr("pbOption")); ui->buttonLayout->addWidget(pbOption, 0, 3); qaSingleMode = new QAction(tr("SingleVoteMode"), this); // 单选模式 qaSingleMode->setCheckable(true); qaSingleMode->setChecked(true); // 默认模式 qaMutipleMode = new QAction(tr("MutipleVoteMode"), this); // 多选 qaMutipleMode->setCheckable(true); qaRaceMode = new QAction(tr("RaceVoteMode"), this); // 抢答 qaRaceMode->setCheckable(true); pbOption->addAction(qaSingleMode); pbOption->addAction(qaMutipleMode); pbOption->addAction(qaRaceMode); connect(qaSingleMode, SIGNAL(triggered()), this, SLOT(DoSingleMode())); connect(qaMutipleMode, SIGNAL(triggered()), this, SLOT(DoMutipleMode())); connect(qaRaceMode, SIGNAL(triggered()), this, SLOT(DoRaceVoteMode())); pbClose = new QPushButton(this); pbClose->setObjectName(tr("pbClose")); ui->buttonLayout->addWidget(pbClose, 0, 4); connect(pbClose, SIGNAL(clicked()), this, SLOT(close())); connect(pbStart, SIGNAL(clicked()), this, SLOT(VoteStart())); connect(pbAuto, SIGNAL(clicked()), this, SLOT(VoteAuto())); connect(pbPause, SIGNAL(clicked()), this, SLOT(VotePause())); connect(pbStop, SIGNAL(clicked()), this, SLOT(VoteStop())); connect(pbResult, SIGNAL(clicked()), this, SLOT(DoShowResults())); drawer = new DianVoteDrawer(); drawer->setWindowIcon(*windowIcon); drawer->setWindowTitle(tr("Result")); connect(pbClose, SIGNAL(clicked()), this->drawer, SLOT(close())); connect(this, SIGNAL(setOptionNum(int)), drawer->histgram, SLOT(SetOptionNums(int))); connect(this, SIGNAL(setOptionNum(int)), drawer->pie, SLOT(SetOptionNums(int))); connect(this, SIGNAL(clearDrawData()), drawer->histgram, SLOT(ClearData())); connect(this, SIGNAL(clearDrawData()), drawer->pie, SLOT(ClearData())); connect(this, SIGNAL(updateGraph(int)), drawer->histgram, SLOT(HandleData(int))); connect(this, SIGNAL(updateGraph(int)), drawer->pie, SLOT(HandleData(int))); LoadStyleSheet("Default"); // 记录初始化窗口大小 initSize = this->size(); this->setMaximumWidth(this->width()); this->setMaximumHeight(this->height() + 100); this->move(0, 0); // 创建Log文件,并打开,程序退出是关闭 VoteLog->open(QIODevice::WriteOnly | QIODevice::Append); // 初始化log记录链表 log = new QList< RevData* >(); }
int main(int argc, char **argv) { try { /* Registering the below classes as metatypes in order to make them liable to be sent through signal parameters. */ qRegisterMetaType<ObjectType>("ObjectType"); qRegisterMetaType<Exception>("Exception"); qRegisterMetaType<ValidationInfo>("ValidationInfo"); //Install a signal handler to start crashhandler when SIGSEGV or SIGABRT is emitted signal(SIGSEGV, startCrashHandler); signal(SIGABRT, startCrashHandler); Application app(argc,argv); //Loading the application splash screen QSplashScreen splash; QPixmap pix(QPixmap(":imagens/imagens/pgmodeler_splash.png")); splash.setPixmap(pix); splash.setMask(pix.mask()); #ifndef Q_OS_MAC splash.setWindowFlags(Qt::SplashScreen | Qt::FramelessWindowHint); #else splash.setWindowFlags(Qt::SplashScreen | Qt::FramelessWindowHint | Qt::NoDropShadowWindowHint); #endif #ifdef Q_OS_WIN splash.show(); #else splash.showMaximized(); #endif app.processEvents(); //Creates the main form MainWindow fmain; //Loading models via command line on MacOSX are disabled until the file association work correclty on that system #ifndef Q_OS_MAC QStringList params=app.arguments(); params.pop_front(); //If the user specifies a list of files to be loaded if(!params.isEmpty()) fmain.loadModels(params); #endif splash.finish(&fmain); fmain.showMaximized(); return(app.exec()); } catch(Exception &e) { QTextStream ts(stdout); ts << e.getExceptionsText(); return(e.getErrorType()); } }