10#include <QStyledItemDelegate>
19#include <klocalizedstring.h>
52 void paint(QPainter* painter,
const QStyleOptionViewItem& option,
const QModelIndex& index)
const override
57 QPalette::ColorGroup cg = (option.state & QStyle::State_Enabled) ? QPalette::Active : QPalette::Disabled;
58 QPalette::ColorRole cr = (option.state & QStyle::State_Selected) ? QPalette::HighlightedText : QPalette::Text;
59 painter->setPen(option.palette.color(cg, cr));
61 if (option.state & QStyle::State_Selected) {
62 painter->fillRect(option.rect, option.palette.highlight());
65 painter->fillRect(option.rect, option.palette.base());
68 int verticalPadding = (option.rect.height() - painter->fontMetrics().ascent()) / 2;
69 const int correction = -3;
74 option.rect.y() + verticalPadding + painter->fontMetrics().ascent() + correction,
79 QSize
sizeHint(
const QStyleOptionViewItem&,
const QModelIndex &)
const override
93 QString workspaceName = cfg.
readEntry<QString>(
"CurrentWorkspace");
118 QLabel *titleLabel =
new QLabel(
this);
120 titleFont.setBold(
true);
121 titleLabel->setFont(titleFont);
122 titleLabel->setText(title);
128 r.itemChooser->showTaggingBar(
false);
130 r.nameEdit =
new QLineEdit(
this);
131 r.nameEdit->setPlaceholderText(i18n(
"Insert name"));
132 r.nameEdit->setClearButtonEnabled(
true);
134 r.saveButton =
new QPushButton(i18n(
"Save"));
136 int firstRow =
m_layout->rowCount();
137 m_layout->addWidget(titleLabel, firstRow, 0, 1, 2);
138 m_layout->addWidget(r.itemChooser, firstRow + 1, 0, 1, 2);
139 m_layout->addWidget(r.nameEdit, firstRow + 2, 0, 1, 1);
140 m_layout->addWidget(r.saveButton, firstRow + 2, 1, 1, 1);
158 if (name.isEmpty()) {
165 if (!resources.isEmpty()) {
169 if (workspace.isNull()) {
171 workspace->setName(name);
174 workspace->setValid(
true);
175 workspace->setFilename(name.replace(
" ",
"_") + workspace->defaultFileExtension());
200 KoResourceSP res = resources.count() > 0 ? resources.first() :
nullptr;
201 if (res && res->active()) {
220 cfg.
writeEntry(
"CurrentWorkspace", resource->name());
223 mainWindow->restoreWorkspace(workspace);
229 if (!thisWindow)
return;
239 if (dlg.result() != QDialog::Accepted)
return;
241 QString name = dlg.
name();
246 layout->setValid(
true);
251 if (name.isEmpty()) {
252 name = i18n(
"Window Layout");
255 layout->setName(name);
256 layout->setFilename(name.split(
" ").join(
"_") + layout->defaultFileExtension());
272 if (resources.isEmpty())
return;
276 if (res && res->active()) {
288 layout->applyLayout();
295 QWidget::showEvent(event);
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
The KisAllresourcesModel class provides access to the cache database for a particular resource type....
QVector< KoResourceSP > resourcesForName(const QString &name) const
void notifySavingWorkspace(KisWorkspaceResourceSP workspace)
Notify that the workspace is saved and settings should be saved to it.
void writeEntry(const QString &name, const T &value)
T readEntry(const QString &name, const T &defaultValue=T())
QImage layoutThumbnail()
layoutThumbnail
void setName(const QString &name)
bool primaryWorkspaceFollowsFocus() const
bool showImageInAllWindows() const
static KisPart * instance()
void setCurrentResource(KoResourceSP resource)
Sets the item representing the resource as selected.
void setRowHeight(int rowHeight)
Sets the height of the view rows.
static KisAllResourcesModel * resourceModel(const QString &resourceType)
static bool addResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource, QString storageLocation="")
static bool updateResourceWithUserInput(QWidget *widgetParent, KoResourceSP resource)
KisMainWindow * mainWindow() const
QMainWindow * qtMainWindow() const
KisCanvasResourceProvider * canvasResourceProvider()
void setShowImageInAllWindowsEnabled(bool showInAll)
void setPrimaryWorkspaceFollowsFocus(bool enabled, QUuid primaryWindow)
static KisWindowLayoutManager * instance()
static KisWindowLayoutResourceSP fromCurrentWindows(const QString &filename, const QList< QPointer< KisMainWindow > > &mainWindows, bool showImageInAllWindows, bool primaryWorkspaceFollowsFocus, KisMainWindow *primaryWindow)
void slotUpdateWindowLayoutSaveButton()
ChooserWidgets m_workspaceWidgets
ChooserWidgets m_windowLayoutWidgets
void slotSaveWindowLayout()
ChooserWidgets createChooserWidgets(const QString &resourceType, const QString &title)
void showEvent(QShowEvent *) override
KisWorkspaceChooser(KisViewManager *view, QWidget *parent=0)
void workspaceSelected(KoResourceSP resource)
void slotUpdateWorkspaceSaveButton()
~KisWorkspaceChooser() override
void windowLayoutSelected(KoResourceSP resource)
KisWorkspaceDelegate(QObject *parent=0)
void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override
~KisWorkspaceDelegate() override
static const int heightHint
QSize sizeHint(const QStyleOptionViewItem &, const QModelIndex &) const override
Resource for storing of workspaces.
QIcon loadIcon(const QString &name)
const QString WindowLayouts