Krita Source Code Documentation
Loading...
Searching...
No Matches
KisSessionManagerDialog.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2018 Jouni Pentikäinen <joupent@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0-or-later
5 */
8#include <QInputDialog>
9#include <QMessageBox>
10#include <KisPart.h>
13#include <KisResourceModel.h>
14#include <KisMainWindow.h>
15
17
19 : QDialog(parent)
20{
21 setupUi(this);
22
23 // Register the custom event type that is used to defer UI updates
24 if (refreshEventType == -1) {
25 refreshEventType = QEvent::registerEventType();
26 }
27
28 connect(btnNew, SIGNAL(clicked()), this, SLOT(slotNewSession()));
29 connect(btnRename, SIGNAL(clicked()), this, SLOT(slotRenameSession()));
30 connect(btnSwitchTo, SIGNAL(clicked()), this, SLOT(slotSwitchSession()));
31 connect(btnDelete, SIGNAL(clicked()), this, SLOT(slotDeleteSession()));
32 connect(btnClose, SIGNAL(clicked()), this, SLOT(slotClose()));
33 connect(this, SIGNAL(finished(int)), this, SLOT(slotClose()));
34
36 lstSessions->setModel(m_model);
37 lstSessions->setModelColumn(KisAbstractResourceModel::Name);
38 lstSessions->setEditTriggers(QAbstractItemView::NoEditTriggers);
39
40 connect(lstSessions, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(slotSessionDoubleClicked(QModelIndex)));
41
42 connect(lstSessions->selectionModel(), SIGNAL(selectionChanged(QItemSelection, QItemSelection)), this, SLOT(slotModelSelectionChanged(QItemSelection, QItemSelection)));
43
45}
46
48{
49 if (event->type() == (QEvent::Type) refreshEventType) {
50 // Do the actual work of updating the button state when receiving a custom event
51 bool hasSelectedSession = getSelectedSession() != nullptr;
52 btnDelete->setEnabled(hasSelectedSession);
53 btnSwitchTo->setEnabled(hasSelectedSession);
54 btnRename->setEnabled(hasSelectedSession);
55 return true;
56 } else {
57 return QDialog::event(event);
58 }
59}
60
62{
63 // Defer updating the buttons by posting a custom event with low priority to avoid locking against
64 // a non-recursive session lock that may be already held by the thread
65 QApplication::postEvent(this, new QEvent((QEvent::Type) refreshEventType), Qt::LowEventPriority);
66}
67
69{
70 QString name;
71
72 name = QInputDialog::getText(this,
73 i18n("Create session"),
74 i18n("Session name:"), QLineEdit::Normal,
75 name);
76 if (name.isEmpty()) return;
77
78 KisSessionResourceSP session(new KisSessionResource(QString(name)));
79
80 QString filename = name.split(" ").join("_") + session->defaultFileExtension();
81 session->setFilename(filename);
82 session->setName(name);
83 session->storeCurrentWindows();
84
86
88
89}
90
92{
93 QString name = QInputDialog::getText(this,
94 i18n("Rename session"),
95 i18n("New name:"), QLineEdit::Normal
96 );
97 if (name.isNull() || name.isEmpty()) return;
98
100 if (!session) return;
101
104}
105
107{
109 slotClose();
110}
111
113{
115
116 if (session) {
117 bool closed = KisPart::instance()->closeSession(true);
118 if (closed) {
120 }
121 }
122}
123
125{
126 QModelIndex idx = lstSessions->currentIndex();
127 if (idx.isValid()) {
128 KoResourceSP res = m_model->resourceForIndex(idx); // lstSessions uses the same index as m_model
129 return res.dynamicCast<KisSessionResource>();
130 }
131 return nullptr;
132}
133
135{
136 QModelIndex idx = lstSessions->currentIndex();
137 if (idx.isValid()) {
138 m_model->setResourceInactive(lstSessions->currentIndex());
139 }
140}
141
143{
144 hide();
146 if (w && !w->isVisible()) {
147 w->show();
148 }
149}
150
152{
153 QModelIndex idx = lstSessions->currentIndex();
154 if (idx.isValid()) {
155 m_lastSessionId = m_model->data(idx, Qt::UserRole + KisAbstractResourceModel::Id).toInt();
156 }
157}
158
160{
161 for (int i = 0; i < m_model->rowCount(); i++) {
162 QModelIndex idx = m_model->index(i, 0);
163 int id = m_model->data(idx, Qt::UserRole + KisAbstractResourceModel::Id).toInt();
164 if (id == m_lastSessionId) {
165 lstSessions->setCurrentIndex(idx);
166 }
167 }
168
170}
171
172void KisSessionManagerDialog::slotModelSelectionChanged(QItemSelection selected, QItemSelection deselected)
173{
174 (void) selected;
175 (void) deselected;
176
178}
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
bool setResourceInactive(const QModelIndex &index)
Main window for Krita.
bool closeSession(bool keepWindows=false)
Definition KisPart.cpp:406
static KisPart * instance()
Definition KisPart.cpp:131
bool restoreSession(const QString &sessionName)
Definition KisPart.cpp:668
KisMainWindow * currentMainwindow() const
Definition KisPart.cpp:483
void setCurrentSession(KisSessionResourceSP session)
Definition KisPart.cpp:686
The KisResourceModel class provides the main access to resources. It is possible to filter the resour...
KoResourceSP resourceForIndex(QModelIndex index=QModelIndex()) const override
resourceForIndex returns a properly versioned and id'ed resource object
static bool renameResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString resourceName)
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
KisSessionManagerDialog(QWidget *parent=nullptr)
void slotSessionDoubleClicked(QModelIndex item)
void slotModelSelectionChanged(QItemSelection selected, QItemSelection deselected)
KisSessionResourceSP getSelectedSession() const
bool event(QEvent *event) override
typedef void(QOPENGLF_APIENTRYP PFNGLINVALIDATEBUFFERDATAPROC)(GLuint buffer)
const QString Sessions