Commit 608ba308 authored by Tusooa Zhu's avatar Tusooa Zhu 🅱

Add actions and tooltips for snapshot docker

parent 60895f2e
......@@ -228,6 +228,42 @@
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
<Action name="create_snapshot">
<icon></icon>
<text>Create Snapshot</text>
<whatsThis></whatsThis>
<toolTip>Create Snapshot</toolTip>
<iconText></iconText>
<activationFlags>1</activationFlags>
<activationConditions>0</activationConditions>
<shortcut></shortcut>
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
<Action name="switchto_snapshot">
<icon></icon>
<text>Switch to Selected Snapshot</text>
<whatsThis></whatsThis>
<toolTip>Switch to selected snapshot</toolTip>
<iconText></iconText>
<activationFlags>1</activationFlags>
<activationConditions>0</activationConditions>
<shortcut></shortcut>
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
<Action name="remove_snapshot">
<icon></icon>
<text>Remove Selected Snapshot</text>
<whatsThis></whatsThis>
<toolTip>Remove Selected Snapshot</toolTip>
<iconText></iconText>
<activationFlags>1</activationFlags>
<activationConditions>0</activationConditions>
<shortcut></shortcut>
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
</Actions>
......
......@@ -29,6 +29,10 @@
#include <kis_canvas2.h>
#include <kis_icon_utils.h>
#include <kis_action.h>
#include <kis_action_manager.h>
#include <KisViewManager.h>
#include <kis_signal_auto_connection.h>
struct SnapshotDocker::Private
{
......@@ -41,6 +45,7 @@ struct SnapshotDocker::Private
QPointer<QToolButton> bnAdd;
QPointer<QToolButton> bnSwitchTo;
QPointer<QToolButton> bnRemove;
KisSignalAutoConnectionsStore connections;
};
SnapshotDocker::Private::Private()
......@@ -65,16 +70,18 @@ SnapshotDocker::SnapshotDocker()
QVBoxLayout *mainLayout = new QVBoxLayout(widget);
m_d->view->setModel(m_d->model.data());
mainLayout->addWidget(m_d->view);
QHBoxLayout *buttonsLayout = new QHBoxLayout(widget);
m_d->bnAdd->setIcon(KisIconUtils::loadIcon("addlayer"));
connect(m_d->bnAdd, &QToolButton::clicked, m_d->model.data(), &KisSnapshotModel::slotCreateSnapshot);
m_d->bnAdd->setToolTip(i18nc("@info:tooltip", "Create snapshot"));
connect(m_d->bnAdd, &QToolButton::clicked, this, &SnapshotDocker::slotBnAddClicked);
buttonsLayout->addWidget(m_d->bnAdd);
m_d->bnSwitchTo->setIcon(KisIconUtils::loadIcon("draw-freehand")); /// XXX: which icon to use?
connect(m_d->bnSwitchTo, &QToolButton::clicked, m_d->view, &KisSnapshotView::slotSwitchToSelectedSnapshot);
m_d->bnSwitchTo->setToolTip(i18nc("@info:tooltip", "Switch to selected snapshot"));
connect(m_d->bnSwitchTo, &QToolButton::clicked, this, &SnapshotDocker::slotBnSwitchToClicked);
buttonsLayout->addWidget(m_d->bnSwitchTo);
m_d->bnRemove->setIcon(KisIconUtils::loadIcon("deletelayer"));
connect(m_d->bnRemove, &QToolButton::clicked, m_d->view, &KisSnapshotView::slotRemoveSelectedSnapshot);
m_d->bnRemove->setToolTip(i18nc("@info:tooltip", "Remove selected snapshot"));
connect(m_d->bnRemove, &QToolButton::clicked, this, &SnapshotDocker::slotBnRemoveClicked);
buttonsLayout->addWidget(m_d->bnRemove);
mainLayout->addLayout(buttonsLayout);
......@@ -86,6 +93,20 @@ SnapshotDocker::~SnapshotDocker()
{
}
void SnapshotDocker::setViewManager(KisViewManager *viewManager)
{
m_d->connections.clear();
KisAction *action = viewManager->actionManager()->createAction("create_snapshot");
m_d->connections.addConnection(action, &KisAction::triggered,
m_d->model.data(), &KisSnapshotModel::slotCreateSnapshot);
action = viewManager->actionManager()->createAction("switchto_snapshot");
m_d->connections.addConnection(action, &KisAction::triggered,
m_d->view, &KisSnapshotView::slotSwitchToSelectedSnapshot);
action = viewManager->actionManager()->createAction("remove_snapshot");
m_d->connections.addConnection(action, &KisAction::triggered,
m_d->view, &KisSnapshotView::slotRemoveSelectedSnapshot);
}
void SnapshotDocker::setCanvas(KoCanvasBase *canvas)
{
KisCanvas2 *c = dynamic_cast<KisCanvas2 *>(canvas);
......@@ -103,4 +124,28 @@ void SnapshotDocker::unsetCanvas()
setCanvas(0);
}
void SnapshotDocker::slotBnAddClicked()
{
if (m_d->canvas) {
KisAction *action = m_d->canvas->viewManager()->actionManager()->actionByName("create_snapshot");
action->trigger();
}
}
void SnapshotDocker::slotBnSwitchToClicked()
{
if (m_d->canvas) {
KisAction *action = m_d->canvas->viewManager()->actionManager()->actionByName("switchto_snapshot");
action->trigger();
}
}
void SnapshotDocker::slotBnRemoveClicked()
{
if (m_d->canvas) {
KisAction *action = m_d->canvas->viewManager()->actionManager()->actionByName("remove_snapshot");
action->trigger();
}
}
#include "SnapshotDocker.moc"
......@@ -22,13 +22,13 @@
#include <QDockWidget>
#include <QScopedPointer>
#include <KoCanvasObserverBase.h>
#include <kis_mainwindow_observer.h>
#include <klocalizedstring.h>
#include <KoShapeController.h>
#include <KoCanvasBase.h>
class SnapshotDocker : public QDockWidget, public KoCanvasObserverBase
class SnapshotDocker : public QDockWidget, public KisMainwindowObserver
{
Q_OBJECT
public:
......@@ -36,9 +36,16 @@ public:
~SnapshotDocker() override;
QString observerName() override { return "SnapshotDocker"; }
void setViewManager(KisViewManager* viewManager) override;
void setCanvas(KoCanvasBase *canvas) override;
void unsetCanvas() override;
private Q_SLOTS:
void slotBnAddClicked();
void slotBnSwitchToClicked();
void slotBnRemoveClicked();
private:
struct Private;
QScopedPointer<Private> m_d;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment