courseEditDockWidget::courseEditDockWidget(int rn, courseWidget* temp, MapEditorController* controller, QWidget* parent) : QDockWidget(tr("Course edit"), parent), controller(controller) { react_to_changes = true; rownum=rn; cw=temp; QFontMetrics metrics(QApplication::font()); courseWidget::cpVector *ss=reinterpret_cast<courseWidget::cpVector*>(temp->getcontrolpoints(rownum)); QWidget* child_widget = new QWidget(); QBoxLayout* cp_edit_field = new QVBoxLayout(); QGridLayout* layout = new QGridLayout(); QGridLayout* mlayout = new QGridLayout(); x_label.push_back(new QLabel(tr("course"))); x_edit.push_back(new QLineEdit(cw->getcoursename(rownum))); mlayout->addWidget(x_label[0], 0, 0); mlayout->addWidget(x_edit[0], 0, 1); lb_groups=new QLabel(tr("groups")); ed_groups=new QLineEdit(cw->getgroupsname(rownum)); mlayout->addWidget(lb_groups, 1, 0); mlayout->addWidget(ed_groups, 1, 1); lb_event=new QLabel(tr("event")); ed_event=new QLineEdit(cw->geteventname(rownum)); mlayout->addWidget(lb_event, 2, 0); mlayout->addWidget(ed_event, 2, 1); cp_edit_field->addLayout(mlayout); int ccp=0; int nextcol=0; for (unsigned int i=0; i<ss->size(); i++) { if(cw->getcourse(rownum)->asPath()->getCoordinate(i).isDashPoint()) { QString cps=QString::number((nextcol/3*15+(nextcol/3))+ccp); QLabel *nl=new QLabel(cps); QLineEdit *ne=new QLineEdit(ss->at(i)->value("cp_cod")); ne->setFixedSize(metrics.width("8888"),25); x_label.push_back(nl); x_edit.push_back(ne); layout->addWidget(nl, ccp, 0+nextcol); layout->addWidget(ne, ccp, 1+nextcol); SegmentedButtonLayout* button_layout = new SegmentedButtonLayout(); for(int j=0;j<6;j++) { QToolButton* cd_button = newToolButton(i,j,QIcon(":/images/blank_cd.png"), cw->xml_names[j]+cps); connect(cd_button, &QToolButton::clicked, this, &courseEditDockWidget::set_cd_icon); button_layout->addWidget(cd_button); } QBoxLayout* list_buttons_layout = new QHBoxLayout(); list_buttons_layout->setContentsMargins(0,0,0,0); list_buttons_layout->addLayout(button_layout); QWidget* list_buttons_group = new QWidget(); list_buttons_group->setLayout(list_buttons_layout); layout->addWidget(list_buttons_group,ccp,2+nextcol); ccp++; if (ccp>15) { nextcol+=3; ccp=0; } } } cp_edit_field->addLayout(layout); QGridLayout* flayout = new QGridLayout(); lb_to_finish=new QLabel(tr("Last control to finish:")); ed_to_finish=new QLineEdit(cw->getdisttofinish(rownum)); flayout->addWidget(lb_to_finish, 0, 0); flayout->addWidget(ed_to_finish, 1, 0); cp_edit_field->addLayout(flayout); x_button = new QPushButton(tr("Save")); cp_edit_field->addWidget(x_button); QPushButton* x_button1 = new QPushButton(tr("Close")); cp_edit_field->addWidget(x_button1); child_widget->setLayout(cp_edit_field); setWidget(child_widget); connect(x_button, &QPushButton::clicked, this, &courseEditDockWidget::savecourse); connect(x_button1, &QPushButton::clicked, this, &courseEditDockWidget::close); }
MenuToolWidget::MenuToolWidget(const QString title, QWidget* pParent ) : BaseDockWidget( title, pParent, Qt::Tool ) { setWindowFlags(Qt::FramelessWindowHint); //也是去掉标题栏的语句 setTitleBarWidget(new QWidget); QFrame* toolGroup = new QFrame(); toolGroup->setStyleSheet("background-image: url(:icons/b2.jpg)"); setWidget(toolGroup); QGridLayout* layout = new QGridLayout(); openButton = newToolButton(QPixmap(":icons/open.png"), tr("Pencil Tool <b>(N)</b>: Sketch with pencil")); saveButton = newToolButton(QPixmap(":icons/save.png"), tr("Select Tool <b>(V)</b>: Select an object")); loadButton = newToolButton(QPixmap(":icons/mirrorV.png"), tr("Move Tool <b>(Q)</b>: Move an object")); cutButton = newToolButton(QPixmap(":icons/cut.png"), tr("Hand Tool <b>(H)</b>: Move the canvas")); copyButton = newToolButton(QPixmap(":icons/copy.png"), tr("Pen Tool <b>(P)</b>: Sketch with pen")); pasteButton = newToolButton(QPixmap(":icons/paste.png"), tr("Eraser Tool <b>(E)</b>: Erase")); undoButton = newToolButton(QPixmap(":icons/undo.png"), tr("Polyline Tool <b>(Y)</b>: Create line/curves")); recycleButton = newToolButton(QPixmap(":icons/redo.png"), tr("Paint Bucket Tool <b>(K)</b>: Fill selected area with a color")); onionupButton = newToolButton(QPixmap(":icons/onionPrev.png"), tr("Brush Tool <b>(B)</b>: Paint smooth stroke with a brush")); oniondownButton = newToolButton(QPixmap(":icons/onionNext.png"), tr("Eyedropper Tool <b>(I)</b>: Set color from the stage<br><b>[ALT]</b> for instant access")); // pencilButton->setWhatsThis(tr("Pencil Tool (N)")); // selectButton->setWhatsThis(tr("Select Tool (V)")); // moveButton->setWhatsThis(tr("Move Tool (Q)")); // handButton->setWhatsThis(tr("Hand Tool (H)")); // penButton->setWhatsThis(tr("Pen Tool (P)")); // eraserButton->setWhatsThis(tr("Eraser Tool (E)")); // polylineButton->setWhatsThis(tr("Polyline Tool (Y)")); // bucketButton->setWhatsThis(tr("Paint Bucket Tool(K)")); // colouringButton->setWhatsThis(tr("Brush Tool(B)")); // eyedropperButton->setWhatsThis(tr("Eyedropper Tool (I)")); // clearButton->setWhatsThis(tr("Clear Tool")); // smudgeButton->setWhatsThis(tr("Smudge Tool (A)")); // pencilButton->setCheckable(true); // penButton->setCheckable(true); // polylineButton->setCheckable(true); // bucketButton->setCheckable(true); // colouringButton->setCheckable(true); // smudgeButton->setCheckable(true); // eyedropperButton->setCheckable(true); // selectButton->setCheckable(true); // moveButton->setCheckable(true); // handButton->setCheckable(true); // eraserButton->setCheckable(true); // pencilButton->setChecked(true); layout->setMargin(10); layout->setSpacing(10); layout->addWidget(openButton,0,0); //layout->setAlignment(moveButton, Qt::AlignRight); layout->addWidget(saveButton,0,1); //layout->setAlignment(clearButton, Qt::AlignLeft); layout->addWidget(loadButton,0,2); //layout->setAlignment(selectButton, Qt::AlignRight); layout->addWidget(cutButton,0,3); //layout->setAlignment(colouringButton, Qt::AlignLeft); layout->addWidget(copyButton,0,4); //layout->setAlignment(polylineButton, Qt::AlignRight); layout->addWidget(pasteButton,0,5); //layout->setAlignment(smudgeButton, Qt::AlignLeft); layout->addWidget(undoButton,0,6); //layout->setAlignment(penButton, Qt::AlignRight); layout->addWidget(recycleButton,0,7); //layout->setAlignment(handButton, Qt::AlignLeft); layout->addWidget(onionupButton,0,8); //layout->setAlignment(pencilButton, Qt::AlignRight); layout->addWidget(oniondownButton,0,9); //layout->setAlignment(bucketButton, Qt::AlignLeft); toolGroup->setLayout(layout); toolGroup->setMaximumHeight(70); this->setMaximumHeight(70); }
ToolSet::ToolSet() { drawPalette = new QDockWidget(tr("Tools")); QFrame* drawGroup = new QFrame(); drawPalette->setWidget(drawGroup); QGridLayout* drawLay = new QGridLayout(); newToolButton(pencilButton); newToolButton(selectButton); newToolButton(moveButton); newToolButton(handButton); newToolButton(penButton); newToolButton(eraserButton); newToolButton(polylineButton); newToolButton(bucketButton); newToolButton(colouringButton); newToolButton(eyedropperButton); newToolButton(clearButton); newToolButton(magnifyButton); newToolButton(smudgeButton); pencilButton->setWhatsThis("Pencil Tool (N)"); selectButton->setWhatsThis("Select Tool (V)"); moveButton->setWhatsThis("Move Tool (Q)"); handButton->setWhatsThis("Hand Tool (H)"); penButton->setWhatsThis("Pen Tool (P)"); eraserButton->setWhatsThis("Eraser Tool (E)"); polylineButton->setWhatsThis("Polyline Tool (Y)"); bucketButton->setWhatsThis("Paint Bucket Tool(K)"); colouringButton->setWhatsThis("Brush Tool(B)"); eyedropperButton->setWhatsThis("Eyedropper Tool (I)"); clearButton->setWhatsThis("Clear Tool"); magnifyButton->setWhatsThis("Zoom Tool (Z)"); smudgeButton->setWhatsThis("Smudge Tool (A)"); pencilButton->setIcon(QIcon(":icons/pencil2.png")); pencilButton->setToolTip("Pencil Tool <b>(N)</b>: Sketch with pencil"); selectButton->setIcon(QIcon(":icons/select.png")); selectButton->setToolTip("Select Tool <b>(V)</b>: Select an object"); moveButton->setIcon(QIcon(":icons/arrow.png")); moveButton->setToolTip("Move Tool <b>(Q)</b>: Move an object"); handButton->setIcon(QIcon(":icons/hand.png")); handButton->setToolTip("Hand Tool <b>(H)</b>: Move the canvas"); penButton->setIcon(QIcon(":icons/pen.png")); penButton->setToolTip("Pen Tool <b>(P)</b>: Sketch with pen"); eraserButton->setIcon(QIcon(":icons/eraser.png")); eraserButton->setToolTip("Eraser Tool <b>(E)</b>: Erase"); polylineButton->setIcon(QIcon(":icons/polyline.png")); polylineButton->setToolTip("Polyline Tool <b>(Y)</b>: Create line/curves"); bucketButton->setIcon(QIcon(":icons/bucket.png")); bucketButton->setToolTip("Paint Bucket Tool <b>(K)</b>: Fill selected area with a color"); colouringButton->setIcon(QIcon(":icons/brush.png")); colouringButton->setToolTip("Brush Tool <b>(B)</b>: Paint smooth stroke with a brush"); eyedropperButton->setIcon(QIcon(":icons/eyedropper.png")); eyedropperButton->setToolTip("Eyedropper Tool <b>(I)</b>: Set color from the stage"); magnifyButton->setIcon(QIcon(":icons/magnify.png")); magnifyButton->setToolTip("Zoom Tool <b>(Z)</b>: Adjust the zoom level"); magnifyButton->setEnabled(false); smudgeButton->setIcon(QIcon(":icons/smudge.png")); smudgeButton->setToolTip("Smudge Tool <b>(A)</b>: Edit polyline/curves"); smudgeButton->setEnabled(true); clearButton->setIcon(QIcon(":icons/clear.png")); clearButton->setToolTip("Clear Tool <b>(L)</b>: Erases content of selected frame"); pencilButton->setCheckable(true); penButton->setCheckable(true); polylineButton->setCheckable(true); bucketButton->setCheckable(true); colouringButton->setCheckable(true); smudgeButton->setCheckable(true); eyedropperButton->setCheckable(true); selectButton->setCheckable(true); moveButton->setCheckable(true); handButton->setCheckable(true); eraserButton->setCheckable(true); pencilButton->setChecked(true); drawLay->setMargin(2); drawLay->setSpacing(0); drawLay->addWidget(moveButton,0,0); drawLay->setAlignment(moveButton, Qt::AlignRight); drawLay->addWidget(clearButton,0,1); drawLay->setAlignment(clearButton, Qt::AlignLeft); drawLay->addWidget(selectButton,1,0); drawLay->setAlignment(selectButton, Qt::AlignRight); drawLay->addWidget(colouringButton,1,1); drawLay->setAlignment(colouringButton, Qt::AlignLeft); drawLay->addWidget(polylineButton,2,0); drawLay->setAlignment(polylineButton, Qt::AlignRight); drawLay->addWidget(smudgeButton,2,1); drawLay->setAlignment(smudgeButton, Qt::AlignLeft); drawLay->addWidget(penButton,3,0); drawLay->setAlignment(penButton, Qt::AlignRight); drawLay->addWidget(handButton,3,1); drawLay->setAlignment(handButton, Qt::AlignLeft); drawLay->addWidget(pencilButton,4,0); drawLay->setAlignment(pencilButton, Qt::AlignRight); drawLay->addWidget(bucketButton,4,1); drawLay->setAlignment(bucketButton, Qt::AlignLeft); drawLay->addWidget(eyedropperButton,5,0); drawLay->setAlignment(eyedropperButton, Qt::AlignRight); drawLay->addWidget(eraserButton,5,1); drawLay->setAlignment(eraserButton, Qt::AlignLeft); drawGroup->setLayout(drawLay); drawGroup->setMaximumHeight(6*32+1); drawPalette->setMaximumHeight(200); connect(pencilButton, SIGNAL(clicked()), this, SIGNAL(pencilClick())); connect(selectButton, SIGNAL(clicked()), this, SIGNAL(selectClick())); connect(moveButton, SIGNAL(clicked()), this, SIGNAL(moveClick())); connect(handButton, SIGNAL(clicked()), this, SIGNAL(handClick())); connect(eraserButton, SIGNAL(clicked()), this, SIGNAL(eraserClick())); connect(penButton, SIGNAL(clicked()), this, SIGNAL(penClick())); connect(polylineButton, SIGNAL(clicked()), this, SIGNAL(polylineClick())); connect(bucketButton, SIGNAL(clicked()), this, SIGNAL(bucketClick())); connect(eyedropperButton, SIGNAL(clicked()), this, SIGNAL(eyedropperClick())); connect(colouringButton, SIGNAL(clicked()), this, SIGNAL(colouringClick())); connect(smudgeButton, SIGNAL(clicked()), this, SIGNAL(smudgeClick())); connect(clearButton, SIGNAL(clicked()), this, SIGNAL(clearClick())); connect(pencilButton, SIGNAL(clicked()), this, SLOT(changePencilButton())); connect(selectButton, SIGNAL(clicked()), this, SLOT(changeSelectButton())); connect(moveButton, SIGNAL(clicked()), this, SLOT(changeMoveButton())); connect(handButton, SIGNAL(clicked()), this, SLOT(changeHandButton())); connect(eraserButton, SIGNAL(clicked()), this, SLOT(changeEraserButton())); connect(penButton, SIGNAL(clicked()), this, SLOT(changePenButton())); connect(polylineButton, SIGNAL(clicked()), this, SLOT(changePolylineButton())); connect(bucketButton, SIGNAL(clicked()), this, SLOT(changeBucketButton())); connect(eyedropperButton, SIGNAL(clicked()), this, SLOT(changeEyedropperButton())); connect(colouringButton, SIGNAL(clicked()), this, SLOT(changeColouringButton())); connect(smudgeButton, SIGNAL(clicked()), this, SLOT(changeSmudgeButton())); }
ColorListWidget::ColorListWidget(Map* map, MainWindow* window, QWidget* parent) : QWidget(parent) , map(map) , window(window) { react_to_changes = true; setWhatsThis(Util::makeWhatThis("color_dock_widget.html")); // Color table color_table = new QTableWidget(map->getNumColors(), 7); color_table->setEditTriggers(QAbstractItemView::SelectedClicked | QAbstractItemView::AnyKeyPressed); color_table->setSelectionMode(QAbstractItemView::SingleSelection); color_table->setSelectionBehavior(QAbstractItemView::SelectRows); color_table->verticalHeader()->setVisible(false); color_table->setHorizontalHeaderLabels(QStringList() << QString{} << tr("Name") << tr("Spot color") << tr("CMYK") << tr("RGB") << tr("K.o.") << tr("Opacity") ); color_table->setItemDelegateForColumn(0, new ColorItemDelegate(this)); color_table->setItemDelegateForColumn(6, new PercentageDelegate(this)); color_table->setColumnHidden(6, true); auto new_button_menu = new QMenu(this); (void) new_button_menu->addAction(tr("New"), this, SLOT(newColor())); duplicate_action = new_button_menu->addAction(tr("Duplicate"), this, SLOT(duplicateColor())); duplicate_action->setIcon(QIcon(QString::fromLatin1(":/images/tool-duplicate.png"))); // Buttons auto new_button = newToolButton(QIcon(QString::fromLatin1(":/images/plus.png")), tr("New")); new_button->setPopupMode(QToolButton::DelayedPopup); // or MenuButtonPopup new_button->setMenu(new_button_menu); delete_button = newToolButton(QIcon(QString::fromLatin1(":/images/minus.png")), tr("Delete")); auto add_remove_layout = new SegmentedButtonLayout(); add_remove_layout->addWidget(new_button); add_remove_layout->addWidget(delete_button); move_up_button = newToolButton(QIcon(QString::fromLatin1(":/images/arrow-up.png")), tr("Move Up")); move_up_button->setAutoRepeat(true); move_down_button = newToolButton(QIcon(QString::fromLatin1(":/images/arrow-down.png")), tr("Move Down")); move_down_button->setAutoRepeat(true); auto up_down_layout = new SegmentedButtonLayout(); up_down_layout->addWidget(move_up_button); up_down_layout->addWidget(move_down_button); // TODO: In Mapper >= 0.6, switch to ColorWidget (or generic) translation context. edit_button = newToolButton(QIcon(QString::fromLatin1(":/images/settings.png")), QApplication::translate("OpenOrienteering::MapEditorController", "&Edit").remove(QLatin1Char('&'))); edit_button->setToolButtonStyle(Qt::ToolButtonTextBesideIcon); auto help_button = newToolButton(QIcon(QString::fromLatin1(":/images/help.png")), tr("Help")); help_button->setAutoRaise(true); // The buttons row layout auto buttons_group_layout = new QHBoxLayout(); buttons_group_layout->addLayout(add_remove_layout); buttons_group_layout->addLayout(up_down_layout); buttons_group_layout->addWidget(edit_button); buttons_group_layout->addWidget(new QLabel(QString::fromLatin1(" ")), 1); buttons_group_layout->addWidget(help_button); // The layout of all components below the table auto bottom_layout = new QVBoxLayout(); QStyleOption style_option(QStyleOption::Version, QStyleOption::SO_DockWidget); bottom_layout->setContentsMargins( style()->pixelMetric(QStyle::PM_LayoutLeftMargin, &style_option) / 2, 0, // Covered by the main layout's spacing. style()->pixelMetric(QStyle::PM_LayoutRightMargin, &style_option) / 2, style()->pixelMetric(QStyle::PM_LayoutBottomMargin, &style_option) / 2 ); bottom_layout->addLayout(buttons_group_layout); bottom_layout->addWidget(new QLabel(tr("Double-click a color value to open a dialog."))); // The main layout auto layout = new QVBoxLayout(); layout->setContentsMargins(QMargins()); layout->addWidget(color_table, 1); layout->addLayout(bottom_layout); setLayout(layout); for (int i = 0; i < map->getNumColors(); ++i) addRow(i); auto header_view = color_table->horizontalHeader(); header_view->setSectionResizeMode(QHeaderView::Interactive); header_view->resizeSections(QHeaderView::ResizeToContents); header_view->setSectionResizeMode(0, QHeaderView::Fixed); // Color header_view->resizeSection(0, 32); header_view->setSectionResizeMode(1, QHeaderView::Stretch); // Name header_view->setSectionResizeMode(1, QHeaderView::Interactive); // Spot colors header_view->setSectionResizeMode(5, QHeaderView::Fixed); // Knockout header_view->resizeSection(5, 32); header_view->setSectionsClickable(false); currentCellChange(color_table->currentRow(), 0, 0, 0); // enable / disable move color buttons // Connections connect(color_table, &QTableWidget::cellChanged, this, &ColorListWidget::cellChange); connect(color_table, &QTableWidget::currentCellChanged, this, &ColorListWidget::currentCellChange); connect(color_table, &QTableWidget::cellDoubleClicked, this, &ColorListWidget::editCurrentColor); connect(new_button, &QAbstractButton::clicked, this, &ColorListWidget::newColor); connect(delete_button, &QAbstractButton::clicked, this, &ColorListWidget::deleteColor); connect(move_up_button, &QAbstractButton::clicked, this, &ColorListWidget::moveColorUp); connect(move_down_button, &QAbstractButton::clicked, this, &ColorListWidget::moveColorDown); connect(edit_button, &QAbstractButton::clicked, this, &ColorListWidget::editCurrentColor); connect(help_button, &QAbstractButton::clicked, this, &ColorListWidget::showHelp); connect(map, &Map::colorAdded, this, &ColorListWidget::colorAdded); connect(map, &Map::colorChanged, this, &ColorListWidget::colorChanged); connect(map, &Map::colorDeleted, this, &ColorListWidget::colorDeleted); }