ToolSettings::ToolSettings(tools::ToolController *ctrl, QWidget *parent) : QDockWidget(parent), d(new Private(ctrl)) { setStyleSheet(defaultDockStylesheet()); // Create a widget stack d->widgetStack = new QStackedWidget(this); setWidget(d->widgetStack); for(int i=0;i<tools::Tool::_LASTTOOL;++i) { if(!d->pages[i].settings->getUi()) d->widgetStack->addWidget(d->pages[i].settings->createUi(this)); } setWindowTitle(d->pages[d->currentTool].title); connect(static_cast<tools::BrushSettings*>(getToolSettingsPage(tools::Tool::FREEHAND)), &tools::BrushSettings::colorChanged, this, &ToolSettings::setForegroundColor); connect(static_cast<tools::BrushSettings*>(getToolSettingsPage(tools::Tool::FREEHAND)), &tools::BrushSettings::subpixelModeChanged, this, &ToolSettings::subpixelModeChanged); connect(static_cast<tools::ColorPickerSettings*>(getToolSettingsPage(tools::Tool::PICKER)), &tools::ColorPickerSettings::colorSelected, this, &ToolSettings::setForegroundColor); d->colorDialog = new color_widgets::ColorDialog(this); d->colorDialog->setAlphaEnabled(false); connect(d->colorDialog, &color_widgets::ColorDialog::colorSelected, this, &ToolSettings::setForegroundColor); }
ToolSettings::ToolSettings(QWidget *parent) : QDockWidget(parent), _currentQuickslot(0), _eraserOverride(0), _eraserActive(false) { // Initialize tool slots _toolprops.reserve(QUICK_SLOTS); for(int i=0;i<QUICK_SLOTS;++i) _toolprops.append(tools::ToolsetProperties()); setStyleSheet(defaultDockStylesheet()); // Create quick toolchange slot buttons // We use the buttons as the title bar for this dock. // The widget has special event handling so it can be used // to drag the dock like a normal titlebar QWidget *tb = new QWidget(this); auto *hlayout = new QHBoxLayout(tb); hlayout->setContentsMargins(3, 3, 3, 0); hlayout->setSpacing(0); setTitleBarWidget(tb); QButtonGroup *quickbuttons = new QButtonGroup(this); quickbuttons->setExclusive(true); for(int i=0;i<QUICK_SLOTS;++i) { auto *b = new widgets::ToolSlotButton(tb); b->setCheckable(true); b->setText(QString::number(i+1)); b->setMinimumSize(40, 40); b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); b->setAutoRaise(true); hlayout->addWidget(b); quickbuttons->addButton(b, i); _quickslot[i] = b; } connect(quickbuttons, SIGNAL(buttonClicked(int)), this, SLOT(setToolSlot(int))); // Create a widget stack _widgets = new QStackedWidget(this); setWidget(_widgets); _pensettings = new tools::PenSettings("pen", tr("Pen")); _widgets->addWidget(_pensettings->createUi(this)); _brushsettings = new tools::BrushSettings("brush", tr("Brush")); _widgets->addWidget(_brushsettings->createUi(this)); _currenttool = _brushsettings; _smudgesettings = new tools::SmudgeSettings("smudge", tr("Watercolor")); _widgets->addWidget(_smudgesettings->createUi(this)); _erasersettings = new tools::EraserSettings("eraser", tr("Eraser")); _widgets->addWidget(_erasersettings->createUi(this)); _pickersettings = new tools::ColorPickerSettings("picker", tr("Color Picker")); _widgets->addWidget(_pickersettings->createUi(this)); _linesettings = new tools::SimpleSettings("line", tr("Line"), "draw-line", tools::SimpleSettings::Line, true); _widgets->addWidget(_linesettings->createUi(this)); _rectsettings = new tools::SimpleSettings("rectangle", tr("Rectangle"), "draw-rectangle", tools::SimpleSettings::Rectangle, false); _widgets->addWidget(_rectsettings->createUi(this)); _ellipsesettings = new tools::SimpleSettings("ellipse", tr("Ellipse"), "draw-ellipse", tools::SimpleSettings::Ellipse, true); _widgets->addWidget(_ellipsesettings->createUi(this)); _fillsettings = new tools::FillSettings("fill", tr("Flood Fill")); _widgets->addWidget(_fillsettings->createUi(this)); _textsettings = new tools::AnnotationSettings("annotation", tr("Annotation")); _widgets->addWidget(_textsettings->createUi(this)); _selectionsettings = new tools::SelectionSettings("selection", tr("Selection (Rectangular)"), false); _widgets->addWidget(_selectionsettings->createUi(this)); _polyselectionsettings = new tools::SelectionSettings("polygonselection", tr("Selection (Free-Form)"), true); _widgets->addWidget(_polyselectionsettings->createUi(this)); _lasersettings = new tools::LaserPointerSettings("laser", tr("Laser pointer")); _widgets->addWidget(_lasersettings->createUi(this)); connect(_pickersettings, SIGNAL(colorSelected(QColor)), this, SLOT(setForegroundColor(QColor))); // Create color changer dialogs _fgdialog = new Color_Dialog(this); _fgdialog->setAlphaEnabled(false); _fgdialog->setWindowTitle(tr("Foreground Color")); connect(_fgdialog, SIGNAL(colorSelected(QColor)), this, SLOT(setForegroundColor(QColor))); _bgdialog = new Color_Dialog(this); _bgdialog->setAlphaEnabled(false); _bgdialog->setWindowTitle(tr("Background Color")); connect(_bgdialog, SIGNAL(colorSelected(QColor)), this, SLOT(setBackgroundColor(QColor))); }
ToolSettings::ToolSettings(tools::ToolController *ctrl, QWidget *parent) : QDockWidget(parent), m_settingspage{}, m_ctrl(ctrl), _currentQuickslot(0), _eraserOverride(0), _eraserActive(false) { Q_ASSERT(ctrl); // Initialize tool slots _toolprops.reserve(QUICK_SLOTS); for(int i=0;i<QUICK_SLOTS;++i) _toolprops.append(tools::ToolsetProperties()); setStyleSheet(defaultDockStylesheet()); // Create quick toolchange slot buttons // We use the buttons as the title bar for this dock. // The widget has special event handling so it can be used // to drag the dock like a normal titlebar QWidget *tb = new QWidget(this); auto *hlayout = new QHBoxLayout(tb); hlayout->setContentsMargins(3, 3, 3, 0); hlayout->setSpacing(0); setTitleBarWidget(tb); QButtonGroup *quickbuttons = new QButtonGroup(this); quickbuttons->setExclusive(true); for(int i=0;i<QUICK_SLOTS;++i) { auto *b = new widgets::ToolSlotButton(tb); b->setCheckable(true); b->setText(QString::number(i+1)); b->setMinimumSize(40, 40); b->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred); b->setAutoRaise(true); hlayout->addWidget(b); quickbuttons->addButton(b, i); _quickslot[i] = b; } connect(quickbuttons, SIGNAL(buttonClicked(int)), this, SLOT(setToolSlot(int))); // Create a widget stack m_widgets = new QStackedWidget(this); setWidget(m_widgets); addPage(tools::Tool::PEN, new tools::PenSettings("pen", tr("Pen"), m_ctrl)); addPage(tools::Tool::BRUSH, new tools::BrushSettings("brush", tr("Brush"), m_ctrl)); addPage(tools::Tool::SMUDGE, new tools::SmudgeSettings("smudge", tr("Watercolor"), m_ctrl)); addPage(tools::Tool::ERASER, new tools::EraserSettings("eraser", tr("Eraser"), m_ctrl)); addPage(tools::Tool::PICKER, new tools::ColorPickerSettings("picker", tr("Color Picker"), m_ctrl)); addPage(tools::Tool::LINE, new tools::SimpleSettings("line", tr("Line"), "draw-line", tools::SimpleSettings::Line, true, m_ctrl)); addPage(tools::Tool::RECTANGLE, new tools::SimpleSettings("rectangle", tr("Rectangle"), "draw-rectangle", tools::SimpleSettings::Rectangle, false, m_ctrl)); addPage(tools::Tool::ELLIPSE, new tools::SimpleSettings("ellipse", tr("Ellipse"), "draw-ellipse", tools::SimpleSettings::Ellipse, true, m_ctrl)); addPage(tools::Tool::FLOODFILL, new tools::FillSettings("fill", tr("Flood Fill"), m_ctrl)); addPage(tools::Tool::ANNOTATION, new tools::AnnotationSettings("annotation", tr("Annotation"), m_ctrl)); addPage(tools::Tool::SELECTION, new tools::SelectionSettings("selection", tr("Selection (Rectangular)"), false, m_ctrl)); addPage(tools::Tool::POLYGONSELECTION, new tools::SelectionSettings("polygonselection", tr("Selection (Free-Form)"), true, m_ctrl)); addPage(tools::Tool::LASERPOINTER, new tools::LaserPointerSettings("laser", tr("Laser pointer"), m_ctrl)); _currenttool = getToolSettingsPage(tools::Tool::BRUSH); connect(static_cast<tools::ColorPickerSettings*>(getToolSettingsPage(tools::Tool::PICKER)), &tools::ColorPickerSettings::colorSelected, this, &ToolSettings::setForegroundColor); // Create color changer dialogs _fgdialog = new color_widgets::ColorDialog(this); _fgdialog->setAlphaEnabled(false); _fgdialog->setWindowTitle(tr("Foreground Color")); connect(_fgdialog, SIGNAL(colorSelected(QColor)), this, SLOT(setForegroundColor(QColor))); }