QPushButton * ControlUnitDialog::addFunction(QString title, QIcon icon, bool checkable) { QPushButton *button = new QPushButton(selection_groupBox); selButtons_verticalLayout->insertWidget(_selButtons.size(), button); button->setFixedWidth(160); button->setFixedHeight(35); button->setCheckable(checkable); button->setAutoExclusive(checkable); // Icon: button->setIconSize(QSize(22, 22)); button->setIcon(icon); // Font: QFont font = button->font(); font.setFamily(QApplication::font().family()); font.setBold(false); font.setPixelSize(13); // 10pts button->setFont(font); // Text: prepend/append spaces to achieve proper icon positions: QFontMetrics fm(font); title = title.trimmed(); int targetstrsize = button->size().width() - button->iconSize().width() - 18; int barestrsize = fm.size(Qt::TextShowMnemonic, title).width(); if (barestrsize < targetstrsize) { double spacesize = fm.size(Qt::TextShowMnemonic, " ").width(); int nspaces = static_cast<int>((targetstrsize - barestrsize) / spacesize + 0.5); title.prepend( QString( nspaces/2, ' ' ) ); title.append( QString( nspaces - nspaces/2, ' ' ) ); } button->setText(title); // Save, show and return button: button->show(); _selButtons.push_back(button); return button; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { // set working dir to executable work directory QDir::setCurrent(QCoreApplication::applicationDirPath()); QString resDir = ResourceFinder::getPath(); //chess::FuncT *f = new chess::FuncT(); //f->run_pgn_speedtest(); //f->run_polyglot(); /* f->run_pgnt(); f->run_pgn_scant(); */ // reconstruct gameModel this->gameModel = new GameModel(); this->gameModel->restoreGameState(); this->gameModel->getGame()->setTreeWasChanged(true); this->boardViewController = new BoardViewController(gameModel, this); this->moveViewController = new MoveViewController(gameModel, this); this->moveViewController->setFocus(); this->engineViewController = new EngineView(gameModel, this); engineViewController->setFocusPolicy(Qt::NoFocus); moveViewController->setFocusPolicy(Qt::ClickFocus); this->name = new QLabel(); name->setText("<b>Robert James Fisher - Reuben Fine</b><br/>New York(USA) 1963.03.??"); name->setAlignment(Qt::AlignCenter); name->setBuddy(moveViewController); QHBoxLayout *hbox_name_editHeader = new QHBoxLayout(); QPushButton *editHeader = new QPushButton(); QPixmap pxEditHeader(*this->fromSvgToPixmap(editHeader->iconSize(),resDir + "/res/icons/document-properties.svg")); editHeader->setIcon(QIcon(pxEditHeader)); hbox_name_editHeader->addStretch(1); hbox_name_editHeader->addWidget(this->name); hbox_name_editHeader->addStretch(1); hbox_name_editHeader->addWidget(editHeader); this->uciController = new UciController(); this->modeController = new ModeController(gameModel, uciController, this); this->editController = new EditController(gameModel, this); this->fileController = new FileController(gameModel, this); QSize btnSize = QSize(this->height()/19, this->height()/19); QSize btnSizeLR = QSize(this->height()/14, this->height()/14); QPushButton *left = new QPushButton(); QPushButton *right = new QPushButton(); QPushButton *beginning = new QPushButton(); QPushButton *end = new QPushButton(); left->setIconSize(btnSizeLR); right->setIconSize(btnSizeLR); beginning->setIconSize(btnSize); end->setIconSize(btnSize); QPixmap pxRight(*this->fromSvgToPixmap(right->iconSize(),resDir + "/res/icons/go-next.svg")); QPixmap pxLeft(*this->fromSvgToPixmap(left->iconSize(),resDir + "/res/icons/go-previous.svg")); QPixmap pxBeginning(*this->fromSvgToPixmap(left->iconSize(),resDir + "/res/icons/go-first.svg")); QPixmap pxEnd(*this->fromSvgToPixmap(left->iconSize(),resDir + "/res/icons/go-last.svg")); right->setIcon(QIcon(pxRight)); left->setIcon(QIcon(pxLeft)); beginning->setIcon(QIcon(pxBeginning)); end->setIcon(QIcon(pxEnd)); QWidget *mainWidget = new QWidget(); // setup the main window // consisting of: // // <-------menubar----------------------------> // <chess- -> <label w/ game data -> // <board -> <moves_edit_view----------> // <view -> <engine output view -> QSizePolicy *spLeft = new QSizePolicy(); spLeft->setHorizontalStretch(1); QSizePolicy *spRight = new QSizePolicy(); spRight->setHorizontalStretch(2); QHBoxLayout *hbox_buttons = new QHBoxLayout(); hbox_buttons->addStretch(1); hbox_buttons->addWidget(beginning); hbox_buttons->addWidget(left); hbox_buttons->addWidget(right); hbox_buttons->addWidget(end); hbox_buttons->addStretch(1); QHBoxLayout *hbox_right_engine_buttons = new QHBoxLayout(); this->pbEngineOnOff = new OnOffButton(this); //new QPushButton("OFF"); this->lblMultiPv = new QLabel(this->tr("Lines:"), this); this->spinMultiPv = new QSpinBox(this); this->spinMultiPv->setRange(1,4); this->spinMultiPv->setValue(1); this->lblMultiPv->setBuddy(this->spinMultiPv); QPushButton *editEngines = new QPushButton(); QPixmap pxEditEngines(*this->fromSvgToPixmap(editEngines->iconSize(),resDir + "/res/icons/document-properties.svg")); editEngines->setIcon(QIcon(pxEditEngines)); hbox_right_engine_buttons->addWidget(pbEngineOnOff); hbox_right_engine_buttons->addWidget(this->lblMultiPv); hbox_right_engine_buttons->addWidget(this->spinMultiPv); hbox_right_engine_buttons->addStretch(1); hbox_right_engine_buttons->addWidget(editEngines); QVBoxLayout *vbox_right = new QVBoxLayout(); vbox_right->addLayout(hbox_name_editHeader); vbox_right->addWidget(moveViewController); vbox_right->addLayout(hbox_buttons); vbox_right->setStretch(0,1); vbox_right->setStretch(1,4); vbox_right->setStretch(2,1); QVBoxLayout *vbox_left = new QVBoxLayout(); vbox_left->addWidget(boardViewController); QWidget *lHboxWidget = new QWidget(this); lHboxWidget->setLayout(vbox_left); QWidget *rHboxWidget = new QWidget(this); rHboxWidget->setLayout(vbox_right); this->splitterLeftRight = new QSplitter(this); splitterLeftRight->addWidget(lHboxWidget); splitterLeftRight->addWidget(rHboxWidget); QSplitterHandle *handleLeftRight = splitterLeftRight->handle(1); QHBoxLayout *layoutSplitterLeftRight = new QHBoxLayout(handleLeftRight); layoutSplitterLeftRight->setSpacing(0); layoutSplitterLeftRight->setMargin(0); QFrame *frameLeftRight = new QFrame(handleLeftRight); frameLeftRight->setFrameShape(QFrame::VLine); frameLeftRight->setFrameShadow(QFrame::Sunken); layoutSplitterLeftRight->addWidget(frameLeftRight); this->splitterTopDown = new QSplitter(this); splitterTopDown->addWidget(splitterLeftRight); splitterTopDown->setOrientation(Qt::Vertical); QVBoxLayout *completeLayout = new QVBoxLayout(); completeLayout->addLayout(hbox_right_engine_buttons); completeLayout->addWidget(engineViewController); QWidget* bottomWidget = new QWidget(this); bottomWidget->setLayout(completeLayout); splitterTopDown->addWidget(bottomWidget); QHBoxLayout *completeLayoutWithSplitter = new QHBoxLayout(); completeLayoutWithSplitter->addWidget(splitterTopDown); QSplitterHandle *handleTopDown = splitterTopDown->handle(1); QHBoxLayout *layoutSplitterTopDown = new QHBoxLayout(handleTopDown); layoutSplitterTopDown->setSpacing(0); layoutSplitterTopDown->setMargin(0); QFrame *frameTopDown = new QFrame(handleTopDown); frameTopDown->setFrameShape(QFrame::HLine); frameTopDown->setFrameShadow(QFrame::Sunken); layoutSplitterTopDown->addWidget(frameTopDown); QMenu *m_game = this->menuBar()->addMenu(this->tr("Game")); QAction* actionNewGame = m_game->addAction(this->tr("New...")); QAction* actionOpen = m_game->addAction(this->tr("Open File")); QAction* actionSaveAs = m_game->addAction("Save Current Game As"); m_game->addSeparator(); QAction* actionPrintGame = m_game->addAction(this->tr("Print Game")); QAction* actionPrintPosition = m_game->addAction(this->tr("Print Position")); QAction *save_diagram = m_game->addAction(this->tr("Save Position as Image...")); m_game->addSeparator(); QAction *actionQuit = m_game->addAction(this->tr("Quit")); actionNewGame->setShortcut(QKeySequence::New); actionOpen->setShortcut(QKeySequence::Open); //save_game->setShortcut(QKeySequence::Save); actionSaveAs->setShortcut(QKeySequence::SaveAs); actionPrintGame->setShortcut(QKeySequence::Print); actionQuit->setShortcut(QKeySequence::Quit); // EDIT MENU QMenu *m_edit = this->menuBar()->addMenu(this->tr("Edit")); QAction *actionCopyGame = m_edit->addAction(this->tr("Copy Game")); QAction *actionCopyPosition = m_edit->addAction(this->tr("Copy Position")); QAction *actionPaste = m_edit->addAction(this->tr("Paste")); m_edit->addSeparator(); QAction *actionEditGameData = m_edit->addAction(this->tr("Edit Game Data")); QAction *actionEnterPosition = m_edit->addAction(this->tr("&Enter Position")); m_edit->addSeparator(); QAction *actionFlipBoard = m_edit->addAction(this->tr("&Flip Board")); this->actionShowSearchInfo = m_edit->addAction(this->tr("Show Search &Info")); QAction *actionColorStyle = m_edit->addAction(this->tr("Color Style...")); QAction *actionResetLayout = m_edit->addAction(this->tr("Reset Layout")); actionCopyGame->setShortcut(QKeySequence::Copy); actionPaste->setShortcut(QKeySequence::Paste); actionEnterPosition->setShortcut('e'); actionFlipBoard->setCheckable(true); actionFlipBoard->setChecked(false); actionShowSearchInfo->setCheckable(true); actionShowSearchInfo->setChecked(true); // MODE MENU QMenu *m_mode = this->menuBar()->addMenu(this->tr("Mode")); QActionGroup *mode_actions = new QActionGroup(this); this->actionAnalysis = mode_actions->addAction(this->tr("&Analysis Mode")); this->actionPlayWhite = mode_actions->addAction(this->tr("Play as &White")); this->actionPlayBlack = mode_actions->addAction(this->tr("Play as &Black")); this->actionEnterMoves = mode_actions->addAction(this->tr("Enter &Moves")); actionAnalysis->setCheckable(true); actionPlayWhite->setCheckable(true); actionPlayBlack->setCheckable(true); actionEnterMoves->setCheckable(true); mode_actions->setExclusive(true); m_mode->addAction(actionAnalysis); m_mode->addAction(actionPlayWhite); m_mode->addAction(actionPlayBlack); m_mode->addAction(actionEnterMoves); m_mode->addSeparator(); QAction* actionFullGameAnalysis = m_mode->addAction(this->tr("Full Game Analysis")); QAction* actionEnginePlayout = m_mode->addAction(this->tr("Playout Position")); m_mode->addSeparator(); QAction *actionSetEngines = m_mode->addAction(this->tr("Engines...")); QShortcut *sc_analysis_mode = new QShortcut(QKeySequence(Qt::Key_A), this); sc_analysis_mode->setContext(Qt::ApplicationShortcut); QShortcut *sc_play_white = new QShortcut(QKeySequence(Qt::Key_W), this); sc_play_white->setContext(Qt::ApplicationShortcut); QShortcut *sc_play_black = new QShortcut(QKeySequence(Qt::Key_B), this); sc_play_black->setContext(Qt::ApplicationShortcut); QShortcut *sc_enter_move_mode_m = new QShortcut(QKeySequence(Qt::Key_M), this); QShortcut *sc_enter_move_mode_esc = new QShortcut(QKeySequence(Qt::Key_Escape), this); sc_enter_move_mode_m->setContext(Qt::ApplicationShortcut); sc_enter_move_mode_esc->setContext(Qt::ApplicationShortcut); // DATABASE MENU QMenu *m_database = this->menuBar()->addMenu(this->tr("Database")); QAction* actionDatabaseWindow = m_database->addAction(this->tr("Browse Games")); QAction* actionLoadNextGame = m_database->addAction(this->tr("Next Game")); QAction* actionLoadPreviousGame = m_database->addAction(this->tr("Previous Game")); // HELP MENU QMenu *m_help = this->menuBar()->addMenu(this->tr("Help ")); QAction *actionAbout = m_help->addAction(this->tr("About")); QAction *actionHomepage = m_help->addAction(this->tr("Jerry-Homepage")); // TOOLBAR this->toolbar = addToolBar("main toolbar"); this->toolbar->setMovable(false); //this->toolbar->setFixedHeight(72); //this->toolbar->setIconSize(QSize(72,72)); QSize iconSize = toolbar->iconSize() * this->devicePixelRatio(); toolbar->setIconSize(iconSize); if(SHOW_ICON_TEXT) { toolbar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon); } QString doc_new(resDir + "/res/icons/document-new.svg"); QPixmap *tbNew = this->fromSvgToPixmap(iconSize,doc_new); QAction *tbActionNew = toolbar->addAction(QIcon(*tbNew), this->tr("New")); QString doc_open(resDir + "/res/icons/document-open.svg"); QPixmap *tbOpen = this->fromSvgToPixmap(iconSize, doc_open); QAction *tbActionOpen = toolbar->addAction(QIcon(*tbOpen), this->tr("Open")); QString doc_save(resDir + "/res/icons/document-save.svg"); QPixmap *tbSaveAs = this->fromSvgToPixmap(iconSize, doc_save); QAction *tbActionSaveAs = toolbar->addAction(QIcon(*tbSaveAs), this->tr("Save As")); QString doc_print(resDir + "/res/icons/document-print.svg"); QPixmap *tbPrint = this->fromSvgToPixmap(iconSize, doc_print); QAction *tbActionPrint = toolbar->addAction(QIcon(*tbPrint), this->tr("Print")); toolbar->addSeparator(); QString view_ref(resDir + "/res/icons/view-refresh.svg"); QPixmap *tbFlip = this->fromSvgToPixmap(iconSize, view_ref); QAction *tbActionFlip = toolbar->addAction(QIcon(*tbFlip), this->tr("Flip Board")); toolbar->addSeparator(); QString edt_cpy(resDir + "/res/icons/edit-copy-pgn.svg"); QPixmap *tbCopyGame = this->fromSvgToPixmap(iconSize, edt_cpy); QAction *tbActionCopyGame = toolbar->addAction(QIcon(*tbCopyGame), this->tr("Copy Game")); QString cpy_fen(resDir + "/res/icons/edit-copy-fen.svg"); QPixmap *tbCopyPosition = this->fromSvgToPixmap(iconSize, cpy_fen); QAction *tbActionCopyPosition = toolbar->addAction(QIcon(*tbCopyPosition), this->tr("Copy Position")); QString edt_pst(resDir + "/res/icons/edit-paste.svg"); QPixmap *tbPaste = this->fromSvgToPixmap(iconSize, edt_pst); QAction *tbActionPaste = toolbar->addAction(QIcon(*tbPaste), this->tr("Paste")); QString new_brd(resDir + "/res/icons/document-enter-position.svg"); QPixmap *tbEnterPosition = this->fromSvgToPixmap(iconSize, new_brd); QAction *tbActionEnterPosition = toolbar->addAction(QIcon(*tbEnterPosition), this->tr("Enter Position")); toolbar->addSeparator(); QString brd_ana(resDir + "/res/icons/emblem-system.svg"); QPixmap *tbAnalysis = this->fromSvgToPixmap(iconSize, brd_ana); QAction *tbActionAnalysis = toolbar->addAction(QIcon(*tbAnalysis), this->tr("Full Analysis")); toolbar->addSeparator(); QString db_icn(resDir + "/res/icons/database.svg"); QPixmap *tbDatabase = this->fromSvgToPixmap(iconSize, db_icn); QAction *tbActionDatabase = toolbar->addAction(QIcon(*tbDatabase), this->tr("Browse Games")); QString prevGame_icn(resDir + "/res/icons/go-previous.svg"); QPixmap *tbPrevGame = this->fromSvgToPixmap(iconSize, prevGame_icn); QAction *tbActionPrevGame = toolbar->addAction(QIcon(*tbPrevGame), this->tr("Prev. Game")); QString nextGame_icn(resDir + "/res/icons/go-next.svg"); QPixmap *tbNextGame = this->fromSvgToPixmap(iconSize, nextGame_icn); QAction *tbActionNextGame = toolbar->addAction(QIcon(*tbNextGame), this->tr("Next Game")); QWidget* spacer = new QWidget(); spacer->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); toolbar->addWidget(spacer); QString hlp_clc(resDir + "/res/icons/help-browser.svg"); QPixmap *tbHelp = this->fromSvgToPixmap(iconSize, hlp_clc); QAction *tbActionHelp = toolbar->addAction(QIcon(*tbHelp), this->tr("About")); // toolbar shortcuts QShortcut *sc_flip = new QShortcut(QKeySequence(Qt::Key_F), this); sc_flip->setContext(Qt::ApplicationShortcut); QShortcut *sc_enter_pos = new QShortcut(QKeySequence(Qt::Key_E), this); sc_enter_pos->setContext(Qt::ApplicationShortcut); /* // FILE // Game QAction* actionNewGame = this->createAction("document-new", this->tr("New Game"), iconSize); QAction* actionOpen = this->createAction("document-open", this->tr("Open File"), iconSize); QAction* actionSaveAs = this->createAction("document-save", this->tr("Save Current\nGame As"), iconSize); // Print QAction* actionPrintGame = this->createAction("document-print", this->tr("Print Game"), iconSize); QAction* actionPrintPosition = this->createAction("document-print-board", this->tr("Print Position"), iconSize); // Layout QAction* actionColorStyle = this->createAction("applications-graphics", this->tr("Board Style"), iconSize); QAction* actionResetLayout = this->createAction("preferences-system-session", this->tr("Reset Layout"), iconSize); // Quit QAction* actionQuit = this->createAction("system-log-out", this->tr("Exit"), iconSize); // Homepage QAction* actionHomepage = this->createAction("internet-web-browser", this->tr("Homepage"), iconSize); // Help (About) QAction* actionAbout = this->createAction("help-browser", this->tr("About"), iconSize); // START // Game QAction* actionPaste = this->createAction("edit-paste", this->tr("Paste\nGame/Position"), iconSize); QAction* actionCopyGame = this->createAction("edit-copy-pgn", this->tr("Copy Game"), iconSizeSmall); QAction* actionCopyPosition = this->createAction("edit-copy-fen", this->tr("Copy Position"), iconSizeSmall); // Edit QAction* actionEditGameData = this->createAction("edit-copy-fen", this->tr("Edit\nMeta Data"), iconSize); QAction* actionEnterPosition = this->createAction("document-enter-position", this->tr("Setup\nNew Position"), iconSize); QAction* actionFlipBoard = this->createAction("view-refresh", this->tr("Flip Board"), iconSize); //QAction* actionShowSearchInfo = this->createAction("view-refresh", this->tr("Show\nSearch Info"), iconSize); // Mode QAction* actionAnalysis = this->createAction("edit-find", this->tr("Infinite\nAnalysis"), iconSize); QAction* actionPlayWhite = this->createAction("play-white", this->tr("Play\nWhite"), iconSize); QAction* actionPlayBlack = this->createAction("play-black", this->tr("Play\nBlack"), iconSize); QAction* actionEnterMoves = this->createAction("text-pencil", this->tr("Enter\nMoves"), iconSize); // Analysis QAction* actionFullGameAnalysis = this->createAction("edit-find-replace", this->tr("Full\nGame Analysis"), iconSize); QAction* actionEnginePlayout = this->createAction("dialog-information", this->tr("Engine\nPlayout"), iconSize); // Database QAction* actionDatabaseWindow = this->createAction("database", this->tr("Show\nDatabase"), iconSize); QAction* actionLoadPreviousGame = this->createAction("go-previous", this->tr("Previous Game"), iconSizeSmall); QAction* actionLoadNextGame = this->createAction("go-previous", this->tr("Next Game"), iconSizeSmall); */ mainWidget->setLayout(completeLayoutWithSplitter); this->setCentralWidget(mainWidget); QStatusBar *statusbar = this->statusBar(); statusbar->showMessage(""); this->setContextMenuPolicy(Qt::NoContextMenu); // SIGNALS AND SLOTS connect(actionNewGame, &QAction::triggered, this->fileController, &FileController::newGame); connect(actionOpen, &QAction::triggered, this->fileController, &FileController::openGame); connect(actionSaveAs, &QAction::triggered, this->fileController, &FileController::saveAsNewGame); connect(actionPrintGame, &QAction::triggered, this->fileController, &FileController::printGame); connect(actionPrintPosition, &QAction::triggered, this->fileController, &FileController::printPosition); connect(actionColorStyle, &QAction::triggered, modeController, &ModeController::onOptionsClicked); connect(actionResetLayout, &QAction::triggered, this, &MainWindow::resetLayout); connect(actionQuit, &QAction::triggered, this, &QCoreApplication::quit); connect(actionHomepage, &QAction::triggered, this, &MainWindow::goToHomepage); connect(actionAbout, &QAction::triggered, this, &MainWindow::showAbout); connect(actionPaste, &QAction::triggered, this->editController, &EditController::paste); connect(actionCopyGame, &QAction::triggered, this->editController, &EditController::copyGameToClipBoard); connect(actionCopyPosition, &QAction::triggered, this->editController, &EditController::copyPositionToClipBoard); connect(actionEditGameData, &QAction::triggered, editController, &EditController::editHeaders); connect(actionEnterPosition, &QAction::triggered, editController, &EditController::enterPosition); connect(actionFlipBoard, &QAction::triggered, this->boardViewController, &BoardViewController::flipBoard); //connect(actionShowSearchInfo, &QAction::triggered, this->engineViewController, &EngineView::flipShowEval); connect(actionShowSearchInfo, &QAction::triggered, this->engineViewController, &EngineView::flipShowEval); connect(actionAnalysis, &QAction::triggered, modeController, &ModeController::onActivateAnalysisMode); connect(actionEnterMoves, &QAction::triggered, modeController, &ModeController::onActivateEnterMovesMode); connect(actionPlayWhite, &QAction::triggered, modeController, &ModeController::onActivatePlayWhiteMode); connect(actionPlayBlack, &QAction::triggered, modeController, &ModeController::onActivatePlayBlackMode); connect(actionFullGameAnalysis, &QAction::triggered, modeController, &ModeController::onActivateGameAnalysisMode); connect(actionEnginePlayout, &QAction::triggered, modeController, &ModeController::onActivatePlayoutPositionMode); connect(actionSetEngines, &QAction::triggered, this->modeController, &ModeController::onSetEnginesClicked); connect(actionDatabaseWindow, &QAction::triggered, fileController, &FileController::openDatabase); connect(actionLoadNextGame, &QAction::triggered, fileController, &FileController::toolbarNextGameInPGN); connect(actionLoadPreviousGame, &QAction::triggered, fileController, &FileController::toolbarPrevGameInPGN); // toolbar buttons connect(sc_flip, &QShortcut::activated, actionFlipBoard, &QAction::trigger); connect(tbActionNew, &QAction::triggered, actionNewGame, &QAction::trigger); connect(tbActionOpen, &QAction::triggered, actionOpen, &QAction::trigger); connect(tbActionSaveAs, &QAction::triggered, actionSaveAs, &QAction::trigger); connect(tbActionPrint, &QAction::triggered, actionPrintGame, &QAction::trigger); connect(tbActionFlip, &QAction::triggered, actionFlipBoard, &QAction::trigger); connect(tbActionCopyGame, &QAction::triggered, actionCopyGame, &QAction::trigger); connect(tbActionCopyPosition, &QAction::triggered, actionCopyPosition, &QAction::trigger); connect(tbActionPaste, &QAction::triggered, actionPaste, &QAction::trigger); connect(tbActionEnterPosition, &QAction::triggered, actionEnterPosition, &QAction::trigger); connect(tbActionAnalysis, &QAction::triggered, actionFullGameAnalysis, &QAction::trigger); connect(tbActionDatabase, &QAction::triggered, actionDatabaseWindow, &QAction::trigger); connect(tbActionPrevGame, &QAction::triggered, actionLoadPreviousGame, &QAction::trigger); connect(tbActionNextGame, &QAction::triggered, actionLoadNextGame, &QAction::trigger); connect(tbActionHelp, &QAction::triggered, actionAbout, &QAction::trigger); // other signals connect(gameModel, &GameModel::stateChange, this, &MainWindow::onStateChange); connect(gameModel, &GameModel::stateChange, this->boardViewController, &BoardViewController::onStateChange); connect(gameModel, &GameModel::stateChange, this->moveViewController, &MoveViewController::onStateChange); connect(gameModel, &GameModel::stateChange, this->modeController, &ModeController::onStateChange); connect(right, &QPushButton::clicked, this->moveViewController, &MoveViewController::onForwardClick); connect(left, &QPushButton::clicked, this->moveViewController, &MoveViewController::onBackwardClick); connect(editEngines, &QPushButton::clicked, this->modeController, &ModeController::onSetEnginesClicked); connect(pbEngineOnOff, &QPushButton::toggled, this, &MainWindow::onEngineToggle); connect(editHeader, &QPushButton::clicked, editController, &EditController::editHeaders); //connect(enter_moves, &QAction::triggered, modeController, &ModeController::onActivateEnterMovesMode); connect(uciController, &UciController::bestmove, modeController, &ModeController::onBestMove); connect(uciController, &UciController::updateInfo, this->engineViewController, &EngineView::onNewInfo); connect(uciController, &UciController::bestPv, modeController, &ModeController::onBestPv); connect(uciController, &UciController::mateDetected, modeController, &ModeController::onMateDetected); connect(uciController, &UciController::eval, modeController, &ModeController::onEval); connect(fileController, &FileController::newGameEnterMoves, modeController, &ModeController::onActivateEnterMovesMode); connect(fileController, &FileController::newGamePlayBlack, modeController, &ModeController::onActivatePlayBlackMode); connect(fileController, &FileController::newGamePlayWhite, modeController, &ModeController::onActivatePlayWhiteMode); connect(beginning, &QPushButton::pressed, this->moveViewController, &MoveViewController::onSeekToBeginning); connect(end, &QPushButton::pressed, this->moveViewController, &MoveViewController::onSeekToEnd); connect(this->spinMultiPv, qOverload<int>(&QSpinBox::valueChanged), this->modeController, &ModeController::onMultiPVChanged); this->gameModel->setMode(MODE_ENTER_MOVES); this->actionEnterMoves->setChecked(true); gameModel->triggerStateChange(); this->resetLayout(); }
ImageFileDialog::ImageFileDialog(const QVariantList &old, QString imgpath, QWidget *parent) :QDialog(parent), sellist(new QListWidget()), flistview(new QListWidget()), treefile(new QTreeView()), statusBar(new QLabel(this)), okbtn(new QPushButton("确定",this)) { mWindow = (MainWindow*)parent; setWindowFlags(Qt::Widget | Qt::FramelessWindowHint); setModal(true); treefile->header()->setHidden(true); flistview->setProperty(DKEY_EXTMAP,extMap); /* 填弃上一次的数据 */ dirModel = new QFileSystemModel(this); fileModel = new QFileSystemModel(this); this->setFixedSize(1000,600); sellist->setSelectionMode(QAbstractItemView::ExtendedSelection); sellist->setAlternatingRowColors(true); flistview->setSelectionMode(QAbstractItemView::ExtendedSelection); flistview->setAlternatingRowColors(true); flistview->setIconSize(QSize(80,60)); sellist->setIconSize(QSize(80,60)); QMap<QString,QString> navigator; navigator[UP] = ":/icon/icons/go-up.png"; navigator[DOWN] = ":/icon/icons/go-down.png"; navigator[LEFT] = ":/icon/icons/go-previous.png"; navigator[RIGHT] = ":/icon/icons/go-next.png"; QVBoxLayout *mainLayout = new QVBoxLayout(); QHBoxLayout *mh = new QHBoxLayout(); this->setLayout(mainLayout); mainLayout->addLayout(mh); this->setWindowTitle(tr("图片编辑")); QVBoxLayout *v = new QVBoxLayout(); v->setSizeConstraint(QLayout::SetFixedSize); QMapIterator<QString,QString> itmap(navigator); while(itmap.hasNext()) { itmap.next(); QPushButton *btn = new QPushButton(); QPixmap p(itmap.value()); btn->setIconSize(p.size()); p.setMask(p.createMaskFromColor(Qt::white)); btn->setIcon(QIcon(p)); btn->setObjectName(itmap.key()); btn->setFixedSize(btn->iconSize()); v->addWidget(btn); if(!LEFT.compare(itmap.key())) { connect(btn,SIGNAL(clicked(bool)),SLOT(onAddSelectedItems())); }else if(!UP.compare(itmap.key())) { connect(btn,SIGNAL(clicked(bool)),SLOT(onUp())); }else if(!DOWN.compare(itmap.key())) { connect(btn,SIGNAL(clicked(bool)),SLOT(onDown())); }else if(!RIGHT.compare(itmap.key())) { connect(btn,SIGNAL(clicked(bool)),SLOT(onDelSelectedItems())); } } dirModel->setRootPath(imgpath); dirModel->removeColumn(3); dirModel->removeColumn(2); dirModel->setFilter(QDir::NoDotAndDotDot | QDir::AllDirs); filters << "*.bmp" << "*.png" << "*.jpg"; dirModel->setNameFilters(filters); treefile->setModel(dirModel); treefile->setRootIndex(dirModel->index(imgpath)); treefile->setAlternatingRowColors(true); treefile->hideColumn(3); treefile->hideColumn(2); treefile->hideColumn(1); fileModel->setRootPath(imgpath); fileModel->setNameFilters(filters); fileModel->setFilter(QDir::Files); connect(sellist,&QListWidget::clicked, [=](QModelIndex index){ sellist->clearSelection(); sellist->setCurrentIndex(index); findChild<QPushButton*>(UP)->setEnabled(index.row() == 0 ? false : true); findChild<QPushButton*>(DOWN)->setEnabled(index.row() == sellist->count() -1 ? false : true); }); connect(flistview,SIGNAL(doubleClicked(QModelIndex)), SLOT(onListViewDoubleClicked(QModelIndex))); connect(treefile,SIGNAL(clicked(QModelIndex)), SLOT(onTreeViewClicked(QModelIndex))); /* 主布局是水平布局,左(QListWidget),中(垂直布局),右(文件系统) */ mh->addWidget(sellist); mh->addLayout(v); mh->addWidget(flistview); mh->addWidget(treefile); QHBoxLayout *mlayout = new QHBoxLayout(); mlayout->setSizeConstraint(QLayout::SetMaximumSize); QLabel *msg = new QLabel("已经添加的图片数:"); statusBar->setText("0"); mlayout->addWidget(msg); mlayout->addWidget(statusBar); mlayout->addWidget(okbtn); statusBar->setSizePolicy(QSizePolicy::Expanding,QSizePolicy::Fixed); mainLayout->addLayout(mlayout); foreach (QVariant v, old) { // example for v "config/images/digital-0.png" QString str = v.toString(); QString fpath = QDir::currentPath() + BACKSLASH + str; QPixmap pic = mWindow->mImgMap[fpath]; if(pic.isNull()) { pic = mWindow->mImgMap[fpath] = QPixmap(fpath); } QString sname = str.mid(str.lastIndexOf(BACKSLASH)+1); QListWidgetItem *nitem = new QListWidgetItem(pic,sname); sellist->addItem(nitem); selectedMap[sname] = fpath; }