void ToolSettings::selectTool(tools::Type tool) { tools::ToolSettings *ts = getToolSettingsPage(tool); if(!ts) { qWarning("selectTool: invalid tool %d", tool); return; } _currenttool = ts; // Deselect annotation on tool change if(tool != tools::ANNOTATION) { int a = _textsettings->selected(); if(a) _textsettings->setSelection(0); } setWindowTitle(_currenttool->getTitle()); _widgets->setCurrentWidget(_currenttool->getUi()); _currenttool->setForeground(foregroundColor()); _currenttool->setBackground(backgroundColor()); _currenttool->restoreToolSettings(_toolprops[currentToolSlot()].tool(_currenttool->getName())); _toolprops[_currentQuickslot].setCurrentTool(tool); updateToolSlot(currentToolSlot(), true); emit toolChanged(tool); emit sizeChanged(_currenttool->getSize()); updateSubpixelMode(); }
void ToolSettings::swapForegroundBackground() { QColor oldForeground = _foreground; _foreground = _background; _background = oldForeground; _currenttool->setForeground(_foreground); _currenttool->setBackground(_background); _toolprops[_currentQuickslot].setForegroundColor(_foreground); _toolprops[_currentQuickslot].setBackgroundColor(_background); updateToolSlot(_currentQuickslot, false); emit foregroundColorChanged(_foreground); emit backgroundColorChanged(_background); }
void ToolSettings::setBackgroundColor(const QColor& color) { if(color != _background) { _background = color; _currenttool->setBackground(color); _toolprops[_currentQuickslot].setBackgroundColor(color); updateToolSlot(_currentQuickslot, false); if(_bgdialog->isVisible()) _bgdialog->setColor(color); emit backgroundColorChanged(color); } }
void ToolSettings::readSettings() { QSettings cfg; cfg.beginGroup("tools"); int quickslot = qBound(0, cfg.value("slot", 0).toInt(), QUICK_SLOTS-1); _toolprops.clear(); for(int i=0;i<QUICK_SLOTS;++i) { cfg.beginGroup(QString("slot-%1").arg(i)); _toolprops << tools::ToolsetProperties::load(cfg); cfg.endGroup(); updateToolSlot(i, true); } selectToolSlot(quickslot); }
void ToolSettings::selectTool(tools::Tool::Type tool) { tools::ToolSettings *ts = getToolSettingsPage(tool); if(!ts) { qWarning("selectTool: invalid tool %d", tool); return; } _currenttool = ts; setWindowTitle(QStringLiteral("%1. %2").arg(currentToolSlot()+1).arg(_currenttool->getTitle())); m_widgets->setCurrentWidget(_currenttool->getUi()); _currenttool->setForeground(foregroundColor()); _currenttool->restoreToolSettings(_toolprops[currentToolSlot()].tool(_currenttool->getName())); _toolprops[_currentQuickslot].setCurrentTool(tool); updateToolSlot(currentToolSlot(), true); emit toolChanged(tool); emit sizeChanged(_currenttool->getSize()); updateSubpixelMode(); }
ToolSettings::ToolSettings(QWidget *parent) : QDockWidget(parent), _currentQuickslot(0), _eraserOverride(0) { // Initialize tool slots _toolprops.reserve(QUICK_SLOTS); for(int i=0;i<QUICK_SLOTS;++i) _toolprops.append(tools::ToolsetProperties()); // Initialize UI QWidget *w = new QWidget(this); setWidget(w); auto *layout = new QVBoxLayout(w); layout->setMargin(3); auto *hlayout = new QHBoxLayout; hlayout->setContentsMargins(3, 3, 3, 0); layout->addLayout(hlayout); // Create quick toolchange slot buttons QButtonGroup *quickbuttons = new QButtonGroup(this); quickbuttons->setExclusive(true); for(int i=0;i<QUICK_SLOTS;++i) { auto *b = new widgets::ToolSlotButton(w); b->setCheckable(true); b->setText(QString::number(i+1)); b->setMinimumSize(32, 32); b->setAutoRaise(true); hlayout->addWidget(b); quickbuttons->addButton(b, i); _quickslot[i] = b; } connect(quickbuttons, SIGNAL(buttonClicked(int)), this, SLOT(setToolSlot(int))); hlayout->addSpacerItem(new QSpacerItem(10, 1, QSizePolicy::Expanding)); // Create foreground/background color changing widget _fgbgcolor = new widgets::DualColorButton(w); _fgbgcolor->setMinimumSize(32,32); hlayout->addWidget(_fgbgcolor); connect(_fgbgcolor, &widgets::DualColorButton::foregroundChanged, [this](const QColor &c){ _currenttool->setForeground(c); _toolprops[_currentQuickslot].setForegroundColor(c); updateToolSlot(_currentQuickslot, false); emit foregroundColorChanged(c); }); connect(_fgbgcolor, &widgets::DualColorButton::backgroundChanged, [this](const QColor &c){ _currenttool->setBackground(c); _toolprops[_currentQuickslot].setBackgroundColor(c); updateToolSlot(_currentQuickslot, false); emit backgroundColorChanged(c); }); // Create a widget stack _widgets = new QStackedWidget(this); layout->addWidget(_widgets, 1); _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; _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"), icon::fromTheme("draw-line"), tools::SimpleSettings::Line, true); _widgets->addWidget(_linesettings->createUi(this)); _rectsettings = new tools::SimpleSettings("rectangle", tr("Rectangle"), icon::fromTheme("draw-rectangle"), tools::SimpleSettings::Rectangle, false); _widgets->addWidget(_rectsettings->createUi(this)); _ellipsesettings = new tools::SimpleSettings("ellipse", tr("Ellipse"), icon::fromTheme("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")); _widgets->addWidget(_selectionsettings->createUi(this)); _lasersettings = new tools::LaserPointerSettings("laser", tr("Laser pointer")); _widgets->addWidget(_lasersettings->createUi(this)); connect(_pickersettings, SIGNAL(colorSelected(QColor)), _fgbgcolor, SLOT(setForeground(QColor))); // Create color changer dialogs auto dlg_fgcolor = new Color_Dialog(this); dlg_fgcolor->setAlphaEnabled(false); dlg_fgcolor->setWindowTitle(tr("Foreground color")); connect(dlg_fgcolor, SIGNAL(colorSelected(QColor)), this, SLOT(setForegroundColor(QColor))); connect(_fgbgcolor, SIGNAL(foregroundClicked(QColor)), dlg_fgcolor, SLOT(showColor(QColor))); auto dlg_bgcolor = new Color_Dialog(this); dlg_bgcolor->setWindowTitle(tr("Background color")); dlg_bgcolor->setAlphaEnabled(false); connect(dlg_bgcolor, SIGNAL(colorSelected(QColor)), this, SLOT(setBackgroundColor(QColor))); connect(_fgbgcolor, SIGNAL(backgroundClicked(QColor)), dlg_bgcolor, SLOT(showColor(QColor))); }