diff --git a/src/desktop/CMakeLists.txt b/src/desktop/CMakeLists.txt index bd2990f4d..1336c299a 100644 --- a/src/desktop/CMakeLists.txt +++ b/src/desktop/CMakeLists.txt @@ -55,7 +55,6 @@ set ( widgets/userlistwidget.cpp widgets/filmstrip.cpp widgets/resizerwidget.cpp - widgets/presetpie.cpp docks/utils.cpp docks/toolsettingsdock.cpp docks/navigator.cpp diff --git a/src/desktop/mainwindow.cpp b/src/desktop/mainwindow.cpp index 643f62cbd..bd0334fe7 100644 --- a/src/desktop/mainwindow.cpp +++ b/src/desktop/mainwindow.cpp @@ -78,7 +78,6 @@ #include "widgets/netstatus.h" #include "widgets/chatwidget.h" #include "widgets/userlistwidget.h" -#include "widgets/presetpie.h" #include "docks/toolsettingsdock.h" #include "docks/navigator.h" @@ -266,21 +265,6 @@ MainWindow::MainWindow(bool restoreWindowPosition) connect(_viewstatus, SIGNAL(angleChanged(qreal)), _view, SLOT(setRotation(qreal))); connect(_dock_toolsettings, &docks::ToolSettings::toolChanged, this, &MainWindow::toolChanged); - - // Create the tool preset pie menu - m_presetPie = new widgets::PresetPie(_view); - m_presetPie->hide(); - m_presetPie->resize(300, 300); - - connect(_view, &widgets::CanvasView::rightClicked, m_presetPie, &widgets::PresetPie::showAt); - connect(_dock_colors, &docks::ColorBox::colorChanged, m_presetPie, &widgets::PresetPie::setColor); - connect(_dock_toolsettings, &docks::ToolSettings::foregroundColorChanged, m_presetPie, &widgets::PresetPie::setColor); - connect(m_presetPie, &widgets::PresetPie::colorChanged, _dock_colors, &docks::ColorBox::setColor); - connect(m_presetPie, &widgets::PresetPie::colorChanged, _dock_toolsettings, &docks::ToolSettings::setForegroundColor); - connect(m_presetPie, &widgets::PresetPie::presetRequest, this, [this](int slice) { - m_presetPie->setToolPreset(slice, _dock_toolsettings->getCurrentToolProperties()); - }); - connect(m_presetPie, &widgets::PresetPie::toolSelected, _dock_toolsettings, &docks::ToolSettings::setToolAndProps); // Create the chatbox and user list QSplitter *chatsplitter = new QSplitter(Qt::Horizontal, this); @@ -2416,45 +2400,6 @@ void MainWindow::setupActions() helpmenu->addAction(about); helpmenu->addAction(aboutqt); - // - // Tool preset pie menu - // - QAction *showPie = makeAction("showpiemenu", nullptr, tr("Show Preset Pie Menu"), QString(), QKeySequence("z")); - connect(showPie, &QAction::triggered, m_presetPie, &widgets::PresetPie::showAtCursor); - - QAction *assignPie = makeAction("assignpreset", nullptr, tr("Assign Tool To Preset Pie Menu"), QString(), QKeySequence("x")); - connect(assignPie, &QAction::triggered, m_presetPie, &widgets::PresetPie::assignSelectedPreset); - - // Keyboard shortcuts for tool preset slices - QActionGroup *presetActions = new QActionGroup(this); - QActionGroup *setPresetActions = new QActionGroup(this); - for(int i=0;isetObjectName(QString("toolpreset-%1").arg(i)); - q->setShortcut(QKeySequence(QString::number(i+1))); - q->setProperty("toolslotidx", i); - CustomShortcutModel::registerCustomizableAction(q->objectName(), q->text(), q->shortcut()); - presetActions->addAction(q); - addAction(q); - - // Assign preset action - q = new QAction(QString("Set tool preset #%1").arg(i+1), this); - q->setObjectName(QString("settoolpreset-%1").arg(i)); - q->setShortcut(QKeySequence(QString("Ctrl+%1").arg(i+1))); - q->setProperty("toolslotidx", i); - CustomShortcutModel::registerCustomizableAction(q->objectName(), q->text(), q->shortcut()); - setPresetActions->addAction(q); - addAction(q); - } - - connect(presetActions, &QActionGroup::triggered, this, [this](QAction *a) { - m_presetPie->selectPreset(a->property("toolslotidx").toInt()); - }); - connect(setPresetActions, &QActionGroup::triggered, this, [this](QAction *a) { - m_presetPie->assignPreset(a->property("toolslotidx").toInt()); - }); - // Add temporary tool change shortcut detector for(QAction *act : _drawingtools->actions()) act->installEventFilter(_tempToolSwitchShortcut); diff --git a/src/desktop/mainwindow.h b/src/desktop/mainwindow.h index 87b845e9d..88d69baf5 100644 --- a/src/desktop/mainwindow.h +++ b/src/desktop/mainwindow.h @@ -41,7 +41,6 @@ namespace widgets { class ChatBox; class UserList; class ViewStatus; - class PresetPie; } namespace docks { class ToolSettings; @@ -221,7 +220,6 @@ private slots: widgets::NetStatus *m_netstatus; widgets::ViewStatus *_viewstatus; QToolButton *_statusChatButton; - widgets::PresetPie *m_presetPie; dialogs::PlaybackDialog *m_playbackDialog; dialogs::SessionSettingsDialog *m_sessionSettings; diff --git a/src/desktop/widgets/presetpie.cpp b/src/desktop/widgets/presetpie.cpp deleted file mode 100644 index 24eac84de..000000000 --- a/src/desktop/widgets/presetpie.cpp +++ /dev/null @@ -1,354 +0,0 @@ -/* - Drawpile - a collaborative drawing program. - - Copyright (C) 2017 Calle Laakkonen - - Drawpile is free software: you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation, either version 3 of the License, or - (at your option) any later version. - - Drawpile is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with Drawpile. If not, see . -*/ - -#include "presetpie.h" -#include "core/layer.h" -#include "core/shapes.h" -#include "core/brush.h" -#include "core/floodfill.h" -#include "tools/tool.h" -#include "utils/icon.h" -#include "utils/customshortcutmodel.h" - -#include - -#include -#include -#include -#include -#include - -namespace widgets { - -using paintcore::Point; - -PresetPie::PresetPie(QWidget *parent) - : QWidget(parent), m_slice(-1) -{ - setMouseTracking(true); - m_color = new color_widgets::ColorWheel(this); - - connect(m_color, &color_widgets::ColorWheel::colorSelected, this, &PresetPie::colorChanged); - - QSettings cfg; - cfg.beginGroup("tools"); - cfg.beginReadArray("presets"); - for(int i=0;isize(); - QPoint topLeft = p - QPoint(width()/2, height()/2); - - // Constrain within the parent widget - if(topLeft.x() < 0) - topLeft.setX(0); - else if(topLeft.x()+width() > size.width()) - topLeft.setX(size.width() - width()); - - if(topLeft.y() < 0) - topLeft.setY(0); - else if(topLeft.y()+height() > size.height()) - topLeft.setY(size.height() - height()); - - move(topLeft); - show(); -} - -void PresetPie::showAtCursor() -{ - if(isVisible()) - hide(); - else - showAt(parentWidget()->mapFromGlobal(QCursor::pos())); -} - -void PresetPie::setColor(const QColor &c) -{ - m_color->setColor(c); -} - -void PresetPie::setToolPreset(int slice, const tools::ToolProperties &props) -{ - Q_ASSERT(slice >= 0 && slice < SLICES); - m_preset[slice] = props; - m_preview = QPixmap(); - - QSettings cfg; - cfg.beginGroup("tools"); - cfg.beginWriteArray("presets"); - cfg.setArrayIndex(slice); - props.save(cfg); - - update(); -} - -void PresetPie::paintEvent(QPaintEvent *) -{ - if(m_preview.isNull()) - redrawPreview(); - - QPainter p(this); - p.setRenderHint(QPainter::Antialiasing); - p.setPen(Qt::NoPen); - - const int d = qMin(width(), height()); - const QRect rect { (width() - d)/2, (height() - d)/2, d, d }; - const int slices = 8; - - // Draw the background - p.drawPixmap(rect, m_preview); - - // Highlight active slice - if(m_slice>=0) { - p.setBrush(QColor(255, 255, 255, 128)); - p.drawPie(rect, (-(m_slice-SLICE_OFFSET)-0.5)*(360/slices)*16, 16*360/slices); - } -} - -int PresetPie::sliceAt(const QPoint &p) -{ - const int r = qMin(width(), height()) / 2; - const int slices = 8; - const QPoint center {width() / 2, height() / 2}; - - // Is the pointer over a slice - const QPoint dPos = p - center; - const int dist2 = dPos.x()*dPos.x() + dPos.y()*dPos.y(); - if(dist2 < r*r) { - qreal a = qRadiansToDegrees(qAtan2(dPos.y(), dPos.x())) + (360 / SLICES / 2); - if(a<0) - a = 360+a; - - int slice = a * slices / 360; - Q_ASSERT(slice>=0 && slicepos()); - - if(m_slice != prevSlice) - update(); -} - -void PresetPie::mouseReleaseEvent(QMouseEvent *e) -{ - m_slice = sliceAt(e->pos()); - - if(m_slice>=0) { - Q_ASSERT(m_slice < SLICES); - if(e->button() == Qt::MiddleButton) { - emit presetRequest(m_slice); - - } else if(selectPreset(m_slice)) { - hide(); - } - } -} - -void PresetPie::assignSelectedPreset() -{ - if(isVisible() && m_slice>=0) - emit presetRequest(m_slice); -} - -void PresetPie::assignPreset(int i) -{ - if(i >= 0 && i < SLICES) - emit presetRequest(i); -} - -bool PresetPie::selectPreset(int i) -{ - if(i >= 0 && i < SLICES && m_preset[i].toolType() >= 0) { - emit toolSelected(m_preset[i]); - return true; - } - return false; -} - -void PresetPie::leaveEvent(QEvent *e) -{ - QWidget::leaveEvent(e); - hide(); -} - -void PresetPie::resizeEvent(QResizeEvent *e) -{ - const int d = qMin(e->size().width(), e->size().height()) * 0.4; - m_color->resize(d, d); - m_color->move(e->size().width()/2 - d/2, e->size().height()/2 - d/2); -} - -static void drawBrushPreview(const tools::ToolProperties &tool, qreal angle, paintcore::Layer &layer) -{ - Q_ASSERT(layer.width()>0 && layer.width() == layer.height()); - const qreal r = layer.width() / 2.0; - paintcore::PointVector pv; - - // Generate tool specific shape - const QRectF shapeRect(r*0.5, -r/8, r*0.4, r/4); - - switch(tool.toolType()) { - case tools::Tool::LINE: - pv << Point(shapeRect.left(), 0, 1) << Point(shapeRect.right(), 0, 1); - break; - case tools::Tool::RECTANGLE: pv = paintcore::shapes::rectangle(shapeRect); break; - case tools::Tool::ELLIPSE: pv = paintcore::shapes::ellipse(shapeRect); break; - default: - pv = paintcore::shapes::sampleStroke(shapeRect); - } - - // Rotate and position the shape - QTransform t = QTransform().translate(r, r).rotate(angle); - QPointF center; - for(paintcore::Point &p : pv) { - t.map(p.x(), p.y(), &p.rx(), &p.ry()); - center += p; - } - center /= pv.size(); - - // Initialize preview brush - paintcore::Brush brush; - brush.setSize(tool.intValue("size", 1)); - brush.setSize2(tool.intValue("pressuresize", false) ? 1 : brush.size1()); - brush.setOpacity(tool.intValue("opacity", 100) / 100.0); - brush.setOpacity2(tool.boolValue("pressureopacity", false) ? 0 : brush.opacity1()); - brush.setHardness(tool.intValue("hardness", 100) / 100.0); - brush.setHardness2(tool.boolValue("pressurehardness", false) ? 0 : brush.hardness1()); - brush.setSpacing(tool.intValue("spacing", 15)); - brush.setSmudge(tool.intValue("smudge", 0) / 100.0); - brush.setIncremental(tool.boolValue("incremental", true)); - - switch(tool.toolType()) { - case tools::Tool::PEN: - brush.setSubpixel(false); - break; - case tools::Tool::ERASER: - brush.setSubpixel(tool.boolValue("hardedge", true)); - brush.setBlendingMode(paintcore::BlendMode::MODE_ERASE); - break; - case tools::Tool::BRUSH: - case tools::Tool::SMUDGE: - brush.setSubpixel(true); - break; - } - - // Draw the shape - paintcore::StrokeState ss(brush); - for(int i=1;i. -*/ - -#ifndef WIDGET_PRESETPIE_H -#define WIDGET_PRESETPIE_H - -#include "tools/toolproperties.h" - -#include -#include - -namespace color_widgets { class ColorWheel; } - -namespace widgets { - -class PresetPie : public QWidget { - Q_OBJECT -public: - //! Number of slices in the pie - static const int SLICES = 8; - - PresetPie(QWidget *parent=nullptr); - - void setToolPreset(int slot, const tools::ToolProperties &props); - -public slots: - void showAt(const QPoint &p); - void showAtCursor(); - void setColor(const QColor &c); - void assignSelectedPreset(); - - void assignPreset(int i); - bool selectPreset(int i); - -signals: - void colorChanged(const QColor &c); - void toolSelected(const tools::ToolProperties &tool); - - //! User indicated that a preset should be assigned to the given slice - void presetRequest(int slice); - -protected: - void paintEvent(QPaintEvent*) override; - void mouseMoveEvent(QMouseEvent*) override; - void mouseReleaseEvent(QMouseEvent*) override; - void leaveEvent(QEvent *e) override; - void resizeEvent(QResizeEvent *e) override; - -private: - // Rotate the slices so that slice 0 is at the top - static const int SLICE_OFFSET = 2; - - void redrawPreview(); - int sliceAt(const QPoint &p); - - color_widgets::ColorWheel *m_color; - tools::ToolProperties m_preset[SLICES]; - QPixmap m_preview; - int m_slice; -}; - -} - -#endif