[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra/textshape-stylesWidget-PierreSt] plugins/textshape/dialogs: Going a bit further. StylesMan
From: Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date: 2013-02-19 19:45:51
Message-ID: 20130219194551.88F79A6091 () git ! kde ! org
[Download RAW message or body]
Git commit 942583b31cedda90add7b44c24f604f8f03f215e by Pierre Stirnweiss.
Committed on 19/02/2013 at 20:40.
Pushed by pstirnweiss into branch 'textshape-stylesWidget-PierreSt'.
Going a bit further. StylesManager model now creates/save unmanaged
styles (not in KoStyleManager.
Dialog uses this.
M +4 -4 plugins/textshape/dialogs/StylesModel.cpp
M +69 -10 plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp
M +13 -3 plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h
M +112 -92 plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.ui
M +1 -8 plugins/textshape/dialogs/stylemanager/StylesManager.cpp
M +245 -1 plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.cpp
M +12 -3 plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.h
http://commits.kde.org/calligra/942583b31cedda90add7b44c24f604f8f03f215e
diff --git a/plugins/textshape/dialogs/StylesModel.cpp \
b/plugins/textshape/dialogs/StylesModel.cpp index a672ccf..b09f2be 100644
--- a/plugins/textshape/dialogs/StylesModel.cpp
+++ b/plugins/textshape/dialogs/StylesModel.cpp
@@ -144,10 +144,10 @@ QVariant StylesModel::data(const QModelIndex &index, int role) \
const return QVariant();
break;
}
- case AbstractStylesModel::CharacterStylePointer: {
- if (m_modelType != AbstractStylesModel::CharacterStyle) {
- return QVariant();
- }
+ case AbstractStylesModel::CharacterStylePointer: { //Paragraph stylesa re also \
character styles. +// if (m_modelType != AbstractStylesModel::CharacterStyle) \
{ +// return QVariant();
+// }
KoCharacterStyle *charStyle = m_styleManager->characterStyle(id);
if (charStyle) {
QVariant variant;
diff --git a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp \
b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp index \
419edbb..2d51409 100644
--- a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp
+++ b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp
@@ -20,21 +20,31 @@
#include "ParagraphStylesTab.h"
#include "ui_ParagraphStylesTab.h"
-#include <dialogs/AbstractStylesModel.h>
+#include "StylesManagerStylesModel.h"
+
+#include <dialogs/StylesModel.h>
#include <dialogs/StylesDelegate.h>
+#include <KoStyleManager.h>
+#include <KoStyleThumbnailer.h>
+
#include <KDebug>
ParagraphStylesTab::ParagraphStylesTab(QWidget *parent) :
QWidget(parent)
- , ui(new Ui::ParagraphStylesTab)
- , m_sourceModel(0)
- , m_stylesDelegate(new StylesDelegate())
+ , ui(new Ui::ParagraphStylesTab)
+ , m_styleManager(0)
+ , m_thumbnailer(new KoStyleThumbnailer())
+ , m_sourceModel(0)
+ , m_stylesDelegate(new StylesDelegate())
+ , m_paragraphStylesModel(0)
{
ui->setupUi(this);
- ui->paragraphListView->setItemDelegate(m_stylesDelegate);
+// ui->paragraphListView->setItemDelegate(m_stylesDelegate);
connect(ui->paragraphListView, SIGNAL(activated(QModelIndex)), this, \
SLOT(slotStyleSelected(QModelIndex))); + connect(ui->newStyleButton, \
SIGNAL(clicked()), this, SLOT(slotCreateNewStyle())); + \
connect(ui->saveAllStylesButton, SIGNAL(clicked()), this, SLOT(slotSaveStyle()));
connect(ui->characterHighlighting, SIGNAL(capitalizationEnabled(bool)), this, \
SLOT(slotCapitalizationEnabled(bool)));
connect(ui->characterHighlighting, \
SIGNAL(capitalizationChanged(QFont::Capitalization)), this, \
SLOT(slotCapitalizationChanged(QFont::Capitalization))); @@ -81,11 +91,24 @@ void \
ParagraphStylesTab::setDisplay(KoParagraphStyle *style) \
ui->indentSpacing->setDisplay(style); }
-void ParagraphStylesTab::setStylesModel(AbstractStylesModel *model)
+void ParagraphStylesTab::setStyleManager(KoStyleManager *manager)
{
- m_sourceModel = model;
- ui->paragraphListView->setModel(m_sourceModel);
+ Q_ASSERT(manager);
+ if (!manager) {
+ return; //return gracefully but shouldn't happen
+ }
+ m_styleManager = manager;
+
+ m_sourceModel = new StylesModel(m_styleManager, \
AbstractStylesModel::ParagraphStyle); + \
m_sourceModel->setStyleThumbnailer(m_thumbnailer); +
+ m_paragraphStylesModel = new StylesManagerStylesModel();
+ m_paragraphStylesModel->setStylesModel(m_sourceModel);
+ m_paragraphStylesModel->setStyleThumbnailer(m_thumbnailer);
+ m_paragraphStylesModel->setStyleManager(m_styleManager);
+ ui->paragraphListView->setModel(m_paragraphStylesModel);
}
+
void ParagraphStylesTab::slotStyleSelected(const QModelIndex &index)
{
KoParagraphStyle *style = \
static_cast<KoParagraphStyle*>(index.data(AbstractStylesModel::ParagraphStylePointer).value<void*>());
@@ -95,14 +118,50 @@ void ParagraphStylesTab::slotStyleSelected(const QModelIndex \
&index) }
}
+void ParagraphStylesTab::slotCreateNewStyle()
+{
+ KoParagraphStyle *newStyle = \
dynamic_cast<KoParagraphStyle*>(m_paragraphStylesModel->slotCreateNewStyle(ui->paragraphListView->currentIndex()));
+ if (newStyle) {
+ ui->characterHighlighting->setDisplay(newStyle);
+ ui->indentSpacing->setDisplay(newStyle);
+ }
+
+}
+
+void ParagraphStylesTab::slotSaveStyle() //TODO reselect the style
+{
+// KoParagraphStyle *style = \
static_cast<KoParagraphStyle*>(ui->paragraphListView->currentIndex().data(AbstractStylesModel::ParagraphStylePointer).value<void*>());
+// if (style) {
+ m_paragraphStylesModel->saveStyle(ui->paragraphListView->currentIndex());
+
+// }
+}
+
void ParagraphStylesTab::slotCapitalizationEnabled(bool enabled)
{
- kDebug() << "capitalization enabled: " << enabled;
+ KoParagraphStyle *style = \
dynamic_cast<KoParagraphStyle*>(m_paragraphStylesModel->unsavedStyle(ui->paragraphListView->currentIndex()));
+ if (style) {
+ if (enabled && !style->hasProperty(QTextFormat::FontCapitalization)) {
+ style->setFontCapitalization(style->fontCapitalization()); //set the \
capitalisation of the parent/default paragraph style. If none exists, 0 is returned \
by the function, which correspond to the "normal" mixed case font rendering. + \
} + else if (!enable && style->hasProperty(QTextFormat::FontCapitalization)) {
+ style->remove(QTextFormat::FontCapitalization);
+ }
+ ui->paragraphListView->update(ui->paragraphListView->currentIndex());
+ ui->characterHighlighting->setDisplay(style);
+ ui->indentSpacing->setDisplay(style);
+ }
}
void ParagraphStylesTab::slotCapitalizationChanged(QFont::Capitalization \
capitalization) {
- kDebug() << "capitalization changed: " << capitalization;
+ KoParagraphStyle *style = \
dynamic_cast<KoParagraphStyle*>(m_paragraphStylesModel->unsavedStyle(ui->paragraphListView->currentIndex()));
+ if (style) {
+ style->KoCharacterStyle::setFontCapitalization(capitalization);
+ ui->paragraphListView->update(ui->paragraphListView->currentIndex());
+ ui->characterHighlighting->setDisplay(style);
+ ui->indentSpacing->setDisplay(style);
+ }
}
void ParagraphStylesTab::slotUnderlineEnabled(bool enabled)
diff --git a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h \
b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h index 6c45486..c9ee0f3 \
100644
--- a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h
+++ b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h
@@ -26,8 +26,12 @@
#include <QModelIndex>
#include <QWidget>
-class AbstractStylesModel;
+class StylesModel;
class StylesDelegate;
+class StylesManagerStylesModel;
+
+class KoStyleManager;
+class KoStyleThumbnailer;
namespace Ui {
class ParagraphStylesTab;
@@ -41,11 +45,13 @@ public:
explicit ParagraphStylesTab(QWidget *parent = 0);
~ParagraphStylesTab();
- void setStylesModel(AbstractStylesModel *model);
+ void setStyleManager(KoStyleManager *manager);
void setDisplay(KoParagraphStyle *style);
private slots:
void slotStyleSelected(const QModelIndex &index);
+ void slotCreateNewStyle();
+ void slotSaveStyle();
void slotCapitalizationEnabled(bool enabled);
void slotCapitalizationChanged(QFont::Capitalization capitalization);
@@ -85,8 +91,12 @@ private slots:
private:
Ui::ParagraphStylesTab *ui;
- AbstractStylesModel *m_sourceModel;
+ KoStyleManager *m_styleManager;
+ KoStyleThumbnailer *m_thumbnailer;
+
+ StylesModel *m_sourceModel;
StylesDelegate *m_stylesDelegate;
+ StylesManagerStylesModel *m_paragraphStylesModel;
};
#endif // PARAGRAPHSTYLESTAB_H
diff --git a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.ui \
b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.ui index 056884b..004e3e8 \
100644
--- a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.ui
+++ b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.ui
@@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>883</width>
- <height>414</height>
+ <width>472</width>
+ <height>227</height>
</rect>
</property>
<property name="sizePolicy">
@@ -19,97 +19,117 @@
<property name="windowTitle">
<string>Form</string>
</property>
- <layout class="QVBoxLayout" name="verticalLayout">
- <item>
- <layout class="QHBoxLayout" name="horizontalLayout">
- <property name="sizeConstraint">
- <enum>QLayout::SetNoConstraint</enum>
+ <layout class="QGridLayout" name="gridLayout">
+ <item row="0" column="0" colspan="3">
+ <widget class="QListView" name="paragraphListView"/>
+ </item>
+ <item row="0" column="3">
+ <widget class="QTabWidget" name="tabWidget">
+ <property name="currentIndex">
+ <number>0</number>
+ </property>
+ <property name="documentMode">
+ <bool>true</bool>
+ </property>
+ <widget class="QWidget" name="paragraphGeneral">
+ <attribute name="title">
+ <string>Page</string>
+ </attribute>
+ </widget>
+ <widget class="CharacterHighlightingTab" name="characterHighlighting">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <attribute name="title">
+ <string>Font</string>
+ </attribute>
+ </widget>
+ <widget class="ParagraphIndentSpacingTab" name="indentSpacing">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <attribute name="title">
+ <string>Indent/Spacing</string>
+ </attribute>
+ </widget>
+ <widget class="ParagraphLayoutTab" name="paragraphLayout">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <attribute name="title">
+ <string>GeneralLayout</string>
+ </attribute>
+ </widget>
+ <widget class="ParagraphBulletsNumbersTab" name="bulletNumbers">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <attribute name="title">
+ <string>Bullet/Numbers</string>
+ </attribute>
+ </widget>
+ <widget class="ParagraphDecorationsTab" name="decorations">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <attribute name="title">
+ <string>Decorations</string>
+ </attribute>
+ </widget>
+ <widget class="ParagraphDropCapsTab" name="dropCaps">
+ <property name="sizePolicy">
+ <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
+ <horstretch>0</horstretch>
+ <verstretch>0</verstretch>
+ </sizepolicy>
+ </property>
+ <attribute name="title">
+ <string>Drop Caps</string>
+ </attribute>
+ </widget>
+ </widget>
+ </item>
+ <item row="1" column="0">
+ <widget class="QPushButton" name="newStyleButton">
+ <property name="text">
+ <string>New Style</string>
+ </property>
+ </widget>
+ </item>
+ <item row="1" column="1">
+ <spacer name="horizontalSpacer">
+ <property name="orientation">
+ <enum>Qt::Horizontal</enum>
+ </property>
+ <property name="sizeHint" stdset="0">
+ <size>
+ <width>45</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ </item>
+ <item row="1" column="2">
+ <widget class="QPushButton" name="saveAllStylesButton">
+ <property name="text">
+ <string>Save all styles</string>
</property>
- <item>
- <widget class="QListView" name="paragraphListView"/>
- </item>
- <item>
- <widget class="QTabWidget" name="tabWidget">
- <property name="currentIndex">
- <number>0</number>
- </property>
- <property name="documentMode">
- <bool>true</bool>
- </property>
- <widget class="QWidget" name="paragraphGeneral">
- <attribute name="title">
- <string>Page</string>
- </attribute>
- </widget>
- <widget class="CharacterHighlightingTab" name="characterHighlighting">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <attribute name="title">
- <string>Font</string>
- </attribute>
- </widget>
- <widget class="ParagraphIndentSpacingTab" name="indentSpacing">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <attribute name="title">
- <string>Indent/Spacing</string>
- </attribute>
- </widget>
- <widget class="ParagraphLayoutTab" name="paragraphLayout">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <attribute name="title">
- <string>GeneralLayout</string>
- </attribute>
- </widget>
- <widget class="ParagraphBulletsNumbersTab" name="bulletNumbers">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <attribute name="title">
- <string>Bullet/Numbers</string>
- </attribute>
- </widget>
- <widget class="ParagraphDecorationsTab" name="decorations">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <attribute name="title">
- <string>Decorations</string>
- </attribute>
- </widget>
- <widget class="ParagraphDropCapsTab" name="dropCaps">
- <property name="sizePolicy">
- <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
- <horstretch>0</horstretch>
- <verstretch>0</verstretch>
- </sizepolicy>
- </property>
- <attribute name="title">
- <string>Drop Caps</string>
- </attribute>
- </widget>
- </widget>
- </item>
- </layout>
+ </widget>
</item>
</layout>
</widget>
diff --git a/plugins/textshape/dialogs/stylemanager/StylesManager.cpp \
b/plugins/textshape/dialogs/stylemanager/StylesManager.cpp index 3aac589..c099346 \
100644
--- a/plugins/textshape/dialogs/stylemanager/StylesManager.cpp
+++ b/plugins/textshape/dialogs/stylemanager/StylesManager.cpp
@@ -47,14 +47,7 @@ void StylesManager::setStyleManager(KoStyleManager *styleManager)
return; //don't crash but should never happen
}
m_styleManager = styleManager;
-
- StylesModel *stylesModel = new StylesModel(m_styleManager, \
AbstractStylesModel::ParagraphStyle);
- KoStyleThumbnailer *thumbnailer = new KoStyleThumbnailer();
- stylesModel->setStyleThumbnailer(thumbnailer);
-
- StylesManagerStylesModel *paragraphStylesModel = new StylesManagerStylesModel();
- paragraphStylesModel->setStylesModel(stylesModel);
- ui->paragraphTab->setStylesModel(paragraphStylesModel);
+ ui->paragraphTab->setStyleManager(styleManager);
}
void StylesManager::setParagraphStyle(KoParagraphStyle *style)
diff --git a/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.cpp \
b/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.cpp index \
793a7e3..eba9c4f 100644
--- a/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.cpp
+++ b/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.cpp
@@ -19,6 +19,11 @@
#include "StylesManagerStylesModel.h"
+#include <KoCharacterStyle.h>
+#include <KoParagraphStyle.h>
+#include <KoStyleManager.h>
+#include <KoStyleThumbnailer.h>
+
#include <KLocale>
#include <QImage>
@@ -27,6 +32,8 @@
StylesManagerStylesModel::StylesManagerStylesModel(QObject *parent) :
StylesFilteredModelBase(parent)
+ , m_styleManager(0)
+ , m_styleIdCounter(1)
{
}
@@ -40,6 +47,9 @@ Qt::ItemFlags StylesManagerStylesModel::flags(const QModelIndex \
&index) const
if (index.internalId() == NewStyleId || index.internalId() == ExistingStyleId) {
return (Qt::NoItemFlags);
}
+ if (m_proxyToSource.at(index.row()) < 0) { //negative Ids which are not the \
titles (handled above) are new styles + return (Qt::ItemIsSelectable | \
Qt::ItemIsEnabled); + }
return m_sourceModel->flags(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex())); }
@@ -70,6 +80,52 @@ QVariant StylesManagerStylesModel::data(const QModelIndex &index, \
int role) cons }
break;
}
+ case AbstractStylesModel::ParagraphStylePointer: {
+ if (m_sourceModel->stylesType() == AbstractStylesModel::ParagraphStyle) {
+ if (index.internalId() == NewStyleId || index.internalId() == \
ExistingStyleId) { + return 0;
+ }
+ if (m_proxyToSource.at(index.row()) < 0) {
+ QVariant variant;
+ variant.setValue<void*>(m_stylesMap.value(index.internalId()));
+ return variant;
+ }
+ KoParagraphStyle *style = \
static_cast<KoParagraphStyle*>(m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), role).value<void*>()); + if (style) {
+ if (m_stylesMap.contains(style->styleId())) {
+ style = \
dynamic_cast<KoParagraphStyle*>(m_stylesMap.value(style->styleId())); + \
} + }
+ QVariant variant;
+ variant.setValue<void*>(style);
+ return variant;
+ }
+ return 0;
+ break;
+ }
+ case AbstractStylesModel::CharacterStylePointer: {
+ if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+ if (index.internalId() == NewStyleId || index.internalId() == \
ExistingStyleId) { + return 0;
+ }
+ if (m_proxyToSource.at(index.row()) < 0) {
+ QVariant variant;
+ variant.setValue<void*>(m_stylesMap.value(index.internalId()));
+ return variant;
+ }
+ KoCharacterStyle *style = \
static_cast<KoCharacterStyle*>(m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), role).value<void*>()); + if (style) {
+ if (m_stylesMap.contains(style->styleId())) {
+ style = m_stylesMap.value(style->styleId());
+ }
+ }
+ QVariant variant;
+ variant.setValue<void*>(style);
+ return variant;
+ }
+ return 0;
+ break;
+ }
case Qt::DisplayRole: {
if (index.internalId() == NewStyleId) {
return i18n("New Styles");
@@ -81,10 +137,52 @@ QVariant StylesManagerStylesModel::data(const QModelIndex \
&index, int role) cons }
case Qt::DecorationRole: {
if (index.internalId() >= 0) {
+ if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) \
{ + KoCharacterStyle *style = \
static_cast<KoCharacterStyle*>(m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), AbstractStylesModel::CharacterStylePointer).value<void*>()); + \
if (style) { + if (m_stylesMap.contains(style->styleId())) {
+ style = m_stylesMap.value(style->styleId());
+ if (style) {
+ return m_styleThumbnailer->thumbnail(style, 0, \
data(index, Qt::SizeHintRole).toSize(), true); + }
+ return QVariant();
+ }
+ }
+ }
+ else if (m_sourceModel->stylesType() == \
AbstractStylesModel::ParagraphStyle) { + KoParagraphStyle *style = \
static_cast<KoParagraphStyle*>(m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), AbstractStylesModel::ParagraphStylePointer).value<void*>()); + \
if (style) { + if (m_stylesMap.contains(style->styleId())) {
+ style = \
dynamic_cast<KoParagraphStyle*>(m_stylesMap.value(style->styleId())); + \
if (style) { + return m_styleThumbnailer->thumbnail(style, \
data(index, Qt::SizeHintRole).toSize(), true); + }
+ return QVariant();
+ }
+ }
+
+ }
return m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), role); }
else {
- /// TODO: create thumbnail for the new/unsaved style there
+ if (m_sourceModel->stylesType() == AbstractStylesModel::ParagraphStyle) \
{ + KoParagraphStyle *style = \
dynamic_cast<KoParagraphStyle*>(m_stylesMap.value(index.internalId())); + \
if (style) { + return m_styleThumbnailer->thumbnail(style, \
data(index, Qt::SizeHintRole).toSize(), true); + }
+ else {
+ return QVariant();
+ }
+ }
+ else {
+ KoCharacterStyle * style = m_stylesMap.value(index.internalId());
+ if (style) {
+ return m_styleThumbnailer->thumbnail(style, 0, data(index, \
Qt::SizeHintRole).toSize(), true); + }
+ else {
+ return QVariant();
+ }
+ }
}
break;
}
@@ -102,6 +200,9 @@ QVariant StylesManagerStylesModel::data(const QModelIndex &index, \
int role) cons QModelIndex StylesManagerStylesModel::indexForCharacterStyle(const \
KoCharacterStyle &style) const {
if (&style) {
+ if (style.styleId() < 0) {
+ return createIndex(m_proxyToSource.indexOf(style.styleId()), 0, \
style.styleId()); + }
QModelIndex sourceIndex(m_sourceModel->indexForCharacterStyle(style));
if (!sourceIndex.isValid() || (m_sourceToProxy.at(sourceIndex.row()) < 0)) {
@@ -121,6 +222,148 @@ QImage StylesManagerStylesModel::stylePreview(const QModelIndex \
&index, QSize si
return m_sourceModel->stylePreview(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0), size); }
+void StylesManagerStylesModel::setStyleManager(KoStyleManager *sm)
+{
+ Q_ASSERT(sm);
+ m_styleManager = sm;
+}
+
+KoCharacterStyle* StylesManagerStylesModel::slotCreateNewStyle(const QModelIndex \
&index) +{
+ if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+ KoCharacterStyle *selectedStyle = \
static_cast<KoCharacterStyle*>(index.data(AbstractStylesModel::CharacterStylePointer).value<void*>());
+ KoCharacterStyle *newStyle;
+ if (selectedStyle) {
+ newStyle = selectedStyle->clone();
+ }
+ else {
+ newStyle = new KoCharacterStyle();
+ }
+ newStyle->setStyleId(-m_styleIdCounter);
+ newStyle->setName(i18n("Style") + "_" + QString::number(m_styleIdCounter));
+ m_stylesMap.insert(-m_styleIdCounter, newStyle);
+ m_newStylesId.append(-m_styleIdCounter++);
+ beginResetModel();
+ createMapping();
+ endResetModel();
+
+ return newStyle;
+ }
+ else {
+ KoParagraphStyle *selectedStyle = \
static_cast<KoParagraphStyle*>(index.data(AbstractStylesModel::ParagraphStylePointer).value<void*>());
+ KoParagraphStyle *newStyle;
+ if (selectedStyle) {
+ newStyle = selectedStyle->clone();
+ }
+ else {
+ newStyle = new KoParagraphStyle();
+ }
+ newStyle->setStyleId(-m_styleIdCounter);
+ newStyle->setName(i18n("Style") + "_" + QString::number(m_styleIdCounter));
+ m_stylesMap.insert(-m_styleIdCounter, newStyle);
+ m_newStylesId.append(-m_styleIdCounter++);
+ beginResetModel();
+ createMapping();
+ endResetModel();
+
+ return newStyle;
+ }
+ return 0;
+}
+
+KoCharacterStyle* StylesManagerStylesModel::unsavedStyle(const QModelIndex &index)
+{
+ if (index.internalId() == NewStyleId || index.internalId() == ExistingStyleId) {
+ return 0;
+ }
+ if (m_proxyToSource.at(index.row()) < 0) {
+ if (m_stylesMap.contains(m_proxyToSource.at(index.row()))) {
+ return m_stylesMap.value(m_proxyToSource.at(index.row()));
+ }
+ return 0;
+ }
+ if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+ KoCharacterStyle *style = static_cast<KoCharacterStyle*>(data(index, \
AbstractStylesModel::CharacterStylePointer).value<void*>()); + if (!style) {
+ return 0;
+ }
+ if (m_stylesMap.contains(style->styleId())) {
+ return m_stylesMap.value(style->styleId());
+ }
+ else {
+ style = style->clone();
+ m_stylesMap.insert(style->styleId(), style);
+ return style;
+ }
+
+ }
+ else if (m_sourceModel->stylesType() == AbstractStylesModel::ParagraphStyle) {
+ KoParagraphStyle *style = static_cast<KoParagraphStyle*>(data(index, \
AbstractStylesModel::ParagraphStylePointer).value<void*>()); + if (!style) {
+ return 0;
+ }
+ if (m_stylesMap.contains(style->styleId())) {
+ return m_stylesMap.value(style->styleId());
+ }
+ else {
+ style = style->clone();
+ m_stylesMap.insert(style->styleId(), style);
+ return style;
+ }
+ }
+ return 0;
+}
+
+void StylesManagerStylesModel::saveStyle(const QModelIndex &index)
+{
+ Q_ASSERT(m_styleManager);
+ Q_ASSERT(m_sourceModel);
+ if (!m_sourceModel || !m_styleManager) {
+ return;
+ }
+
+ if (index.internalId() == NewStyleId || index.internalId() == ExistingStyleId) {
+ return;
+ }
+ if (m_proxyToSource.at(index.row()) < 0) {
+ if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+ KoCharacterStyle *style = \
m_stylesMap.value(m_proxyToSource.at(index.row())); + \
m_stylesMap.remove(m_proxyToSource.at(index.row())); + \
m_styleManager->add(style); + }
+ else if (m_sourceModel->stylesType() == AbstractStylesModel::ParagraphStyle) \
{ + KoParagraphStyle *style = \
dynamic_cast<KoParagraphStyle*>(m_stylesMap.value(m_proxyToSource.at(index.row()))); \
+ if (style) { + \
m_stylesMap.remove(m_proxyToSource.at(index.row())); + \
m_styleManager->add(style); + }
+ }
+ }
+ else {
+ if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+ KoCharacterStyle *originalStyle = \
static_cast<KoCharacterStyle*>(m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), AbstractStylesModel::CharacterStylePointer).value<void*>()); + \
if (originalStyle) { + beginResetModel();
+ originalStyle->copyProperties(m_stylesMap.value(originalStyle->styleId()));
+ m_stylesMap.remove(originalStyle->styleId());
+ endResetModel();
+ }
+ }
+ else if (m_sourceModel->stylesType() == AbstractStylesModel::ParagraphStyle) \
{ + KoParagraphStyle *originalStyle = \
static_cast<KoParagraphStyle*>(m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), AbstractStylesModel::ParagraphStylePointer).value<void*>()); + \
if (originalStyle) { + KoParagraphStyle *unsavedStyle = \
dynamic_cast<KoParagraphStyle*>(m_stylesMap.value(originalStyle->styleId())); + \
if (unsavedStyle) { + beginResetModel();
+ originalStyle->copyProperties(unsavedStyle);
+ m_stylesMap.remove(originalStyle->styleId());
+ endResetModel();
+ }
+ }
+ }
+ }
+}
+
void StylesManagerStylesModel::createMapping()
{
Q_ASSERT(m_sourceModel);
@@ -147,4 +390,5 @@ void StylesManagerStylesModel::createMapping()
m_sourceToProxy[m_proxyToSource.at(i)] = i;
}
}
+ kDebug() << "m_proxyToSource: " << m_proxyToSource;
}
diff --git a/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.h \
b/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.h index \
1ae9132..848377a 100644
--- a/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.h
+++ b/plugins/textshape/dialogs/stylemanager/StylesManagerStylesModel.h
@@ -22,6 +22,11 @@
#include "dialogs/StylesFilteredModelBase.h"
+#include <QMap>
+#include <QModelIndex>
+
+class KoStyleManager;
+
class StylesManagerStylesModel : public StylesFilteredModelBase
{
Q_OBJECT
@@ -52,7 +57,7 @@ public:
/** Specific methods of the StylesManagerStylesModel. */
-// void setStyleManager(KoStyleManager *sm);
+ void setStyleManager(KoStyleManager *sm);
// void setInitialUsedStyles(QVector<int> usedStyles);
@@ -62,16 +67,20 @@ public:
signals:
public slots:
-// void slotCreateNewStyle();
+ KoCharacterStyle* slotCreateNewStyle(const QModelIndex &index = QModelIndex());
+ KoCharacterStyle* unsavedStyle(const QModelIndex &index);
+ void saveStyle(const QModelIndex &index);
protected:
virtual void createMapping();
private:
-// KoStyleManager *m_styleManager;
+ KoStyleManager *m_styleManager;
// KoParagraphStyle *m_currentParagraphStyle;
// KoCharacterStyle *m_defaultCharacterStyle;
QVector<int> m_newStylesId;
+ QMap<int, KoCharacterStyle*> m_stylesMap;
+ int m_styleIdCounter;
// QVector<int> m_usedStyles;
// QVector<int> m_unusedStyles;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic