[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [calligra/textshape-stylesWidget-PierreSt] /: Change the styles model chain, to simplify things.
From:       Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date:       2013-01-12 13:11:16
Message-ID: 20130112131116.600A2A60DA () git ! kde ! org
[Download RAW message or body]

Git commit 5605ef428ea189d58d6a92fe697e39ac26f6e457 by Pierre Stirnweiss.
Committed on 12/01/2013 at 13:37.
Pushed by pstirnweiss into branch 'textshape-stylesWidget-PierreSt'.

Change the styles model chain, to simplify things.

First, use QModelIndex to communicate between the models and the
widgets. StylesManager still need to be converted, but that will come
when i'll refactor it.
Second, move the character style None, from StylesModel to
DockerStylesComboModel, because it is only used for the combo in the
docker.

M  +2    -3    plugins/textshape/dialogs/AbstractStylesModel.h
M  +1    -1    plugins/textshape/dialogs/CharacterGeneral.cpp
M  +108  -30   plugins/textshape/dialogs/DockerStylesComboModel.cpp
M  +23   -1    plugins/textshape/dialogs/DockerStylesComboModel.h
M  +9    -1    plugins/textshape/dialogs/FormattingPreview.cpp
M  +1    -1    plugins/textshape/dialogs/ParagraphGeneral.cpp
M  +6    -2    plugins/textshape/dialogs/SimpleCharacterWidget.cpp
M  +3    -2    plugins/textshape/dialogs/SimpleParagraphWidget.cpp
M  +0    -1    plugins/textshape/dialogs/StyleManager.cpp
M  +9    -12   plugins/textshape/dialogs/StylesCombo.cpp
M  +3    -1    plugins/textshape/dialogs/StylesCombo.h
M  +6    -17   plugins/textshape/dialogs/StylesFilteredModelBase.cpp
M  +6    -7    plugins/textshape/dialogs/StylesFilteredModelBase.h
M  +14   -105  plugins/textshape/dialogs/StylesModel.cpp
M  +2    -12   plugins/textshape/dialogs/StylesModel.h
M  +-    --    words/templates/Wordprocessing/A4.odt

http://commits.kde.org/calligra/5605ef428ea189d58d6a92fe697e39ac26f6e457

diff --git a/plugins/textshape/dialogs/AbstractStylesModel.h \
b/plugins/textshape/dialogs/AbstractStylesModel.h index 5ff2d56..6fdcb7a 100644
--- a/plugins/textshape/dialogs/AbstractStylesModel.h
+++ b/plugins/textshape/dialogs/AbstractStylesModel.h
@@ -82,11 +82,10 @@ public:
     /** Return a @class QModelIndex for the specified @param style. */
     virtual QModelIndex indexForCharacterStyle(const KoCharacterStyle &style) const \
= 0;  
-    /** Returns a QImage which is a preview of the style specified by @param row of \
the given @param size. +    /** Returns a QImage which is a preview of the style \
                specified by @param index of the given @param size.
       * If size isn't specified, the default size of the given @class \
                KoStyleThumbnailer is used.
     */
-    virtual QImage stylePreview(int row, QSize size = QSize()) = 0;
-//    virtual QImage stylePreview(QModelIndex &index, QSize size = QSize()) = 0;
+    virtual QImage stylePreview(const QModelIndex &index, QSize size = QSize()) = 0;
 
     /** Returns the type of styles in the model */
     virtual AbstractStylesModel::Type stylesType() const = 0;
diff --git a/plugins/textshape/dialogs/CharacterGeneral.cpp \
b/plugins/textshape/dialogs/CharacterGeneral.cpp index d3eead6..66ff384 100644
--- a/plugins/textshape/dialogs/CharacterGeneral.cpp
+++ b/plugins/textshape/dialogs/CharacterGeneral.cpp
@@ -170,8 +170,8 @@ void CharacterGeneral::setStyleManager(KoStyleManager *sm)
 
 void CharacterGeneral::updateNextStyleCombo(KoParagraphStyle *style)
 {
-    widget.nextStyle->setCurrentIndex(m_paragraphStyleModel->indexForParagraphStyle(*style).row());
  m_paragraphStyleModel->setCurrentParagraphStyle(style->styleId());
+    widget.nextStyle->setCurrentItem(m_paragraphStyleModel->indexForParagraphStyle(*style));
  }
 
 int CharacterGeneral::nextStyleId()
diff --git a/plugins/textshape/dialogs/DockerStylesComboModel.cpp \
b/plugins/textshape/dialogs/DockerStylesComboModel.cpp index a669b77..472f8b4 100644
--- a/plugins/textshape/dialogs/DockerStylesComboModel.cpp
+++ b/plugins/textshape/dialogs/DockerStylesComboModel.cpp
@@ -22,6 +22,7 @@
 #include <KoCharacterStyle.h>
 #include <KoParagraphStyle.h>
 #include <KoStyleManager.h>
+#include <KoStyleThumbnailer.h>
 
 #include <KLocale>
 #include <KStringHandler>
@@ -29,11 +30,25 @@
 #include <KDebug>
 
 DockerStylesComboModel::DockerStylesComboModel(QObject *parent) :
-    StylesFilteredModelBase(parent),
-    m_styleManager(0)
+    StylesFilteredModelBase(parent)
+    , m_styleManager(0)
+    , m_currentParagraphStyle(0)
+    , m_defaultCharacterStyle(0)
 {
 }
 
+DockerStylesComboModel::~DockerStylesComboModel()
+{
+    if (m_currentParagraphStyle) {
+        delete m_currentParagraphStyle;
+        m_currentParagraphStyle = 0;
+    }
+    if (m_defaultCharacterStyle) {
+        delete m_defaultCharacterStyle;
+        m_defaultCharacterStyle = 0;
+    }
+}
+
 Qt::ItemFlags DockerStylesComboModel::flags(const QModelIndex &index) const
 {
     if (index.internalId() == UsedStyleId || index.internalId() == UnusedStyleId) {
@@ -77,7 +92,17 @@ QVariant DockerStylesComboModel::data(const QModelIndex &index, \
int role) const  return QVariant();
     }
     case Qt::DecorationRole: {
-        return m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), role); +        if (m_sourceModel->stylesType() == \
AbstractStylesModel::CharacterStyle && index.internalId() == CharacterStyleNoneId) { \
+            KoCharacterStyle *usedStyle = \
static_cast<KoCharacterStyle*>(m_currentParagraphStyle); +            if (!usedStyle) \
{ +                usedStyle = m_defaultCharacterStyle;
+            }
+            usedStyle->setName(i18n("None"));
+            return m_styleThumbnailer->thumbnail(usedStyle, m_currentParagraphStyle, \
data(index, Qt::SizeHintRole).toSize()); +        }
+        else {
+            return m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), role); +        }
         break;
     }
     case Qt::SizeHintRole: {
@@ -88,6 +113,45 @@ QVariant DockerStylesComboModel::data(const QModelIndex &index, \
int role) const  return QVariant();
 }
 
+QModelIndex DockerStylesComboModel::indexForCharacterStyle(const KoCharacterStyle \
&style) const +{
+    if (&style) {
+        QModelIndex sourceIndex(m_sourceModel->indexForCharacterStyle(style));
+
+        if (!sourceIndex.isValid() || (m_sourceToProxy.at(sourceIndex.row()) < 0)) {
+            return QModelIndex();
+        }
+        return createIndex(m_sourceToProxy.at(sourceIndex.row()), 0, \
int(sourceIndex.internalId())); +    }
+    else {
+        if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+            return createIndex((m_proxyToSource.indexOf(CharacterStyleNoneId)), 0, \
CharacterStyleNoneId); +        }
+        return QModelIndex();
+    }
+}
+
+QImage DockerStylesComboModel::stylePreview(const QModelIndex &index, QSize size)
+{
+    if (!index.isValid()) {
+        return QImage();
+    }
+    if (index.internalId() == CharacterStyleNoneId) {
+        KoCharacterStyle *usedStyle = \
static_cast<KoCharacterStyle*>(m_currentParagraphStyle); +        if (!usedStyle) {
+            usedStyle = m_defaultCharacterStyle;
+        }
+        usedStyle->setName(i18n("None"));
+        if (usedStyle->styleId() >= 0) {
+            usedStyle->setStyleId(-usedStyle->styleId()); //this style is not \
managed by the styleManager but its styleId will be used in the thumbnail cache as \
part of the key. +        }
+        return m_styleThumbnailer->thumbnail(usedStyle, m_currentParagraphStyle, \
size); +    }
+    else {
+        return m_sourceModel->stylePreview(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0), size); +    }
+}
+
 void DockerStylesComboModel::setInitialUsedStyles(QVector<int> usedStyles)
 {
     Q_UNUSED(usedStyles);
@@ -99,6 +163,17 @@ void DockerStylesComboModel::setInitialUsedStyles(QVector<int> \
usedStyles)  //    endResetModel();
 }
 
+void DockerStylesComboModel::setStylesModel(AbstractStylesModel *sourceModel)
+{
+    if ((!m_sourceModel || !m_defaultCharacterStyle) && sourceModel->stylesType() == \
AbstractStylesModel::CharacterStyle) { +        m_defaultCharacterStyle = new \
KoCharacterStyle(); +        \
m_defaultCharacterStyle->setStyleId(CharacterStyleNoneId); +        \
m_defaultCharacterStyle->setName(i18n("None")); +        \
m_defaultCharacterStyle->setFontPointSize(12); +    }
+    StylesFilteredModelBase::setStylesModel(sourceModel);
+}
+
 void DockerStylesComboModel::setStyleManager(KoStyleManager *sm)
 {
     Q_ASSERT(sm);
@@ -117,11 +192,9 @@ void DockerStylesComboModel::setStyleManager(KoStyleManager *sm)
                 QVector<int>::iterator begin = m_usedStyles.begin();
                 compareStyle = m_styleManager->characterStyle(i);
                 for ( ; begin != m_usedStyles.end(); ++begin) {
-                    if (m_sourceModel->index(*begin, 0, QModelIndex()).internalId() \
!= -1) { //styleNone (internalId=-1) is a virtual style provided only for the UI. it \
                does not exist in KoStyleManager
-                        KoCharacterStyle *s = \
m_styleManager->characterStyle(m_sourceModel->index(*begin, 0, \
                QModelIndex()).internalId());
-                        if (KStringHandler::naturalCompare(compareStyle->name(), \
                s->name()) < 0) {
-                            break;
-                        }
+                    KoCharacterStyle *s = \
m_styleManager->characterStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId()); +                    if \
(KStringHandler::naturalCompare(compareStyle->name(), s->name()) < 0) { +             \
break;  }
                 }
                 m_usedStyles.insert(begin, \
m_sourceModel->indexForCharacterStyle(*compareStyle).row()); @@ -136,11 +209,9 @@ \
void DockerStylesComboModel::setStyleManager(KoStyleManager *sm)  \
QVector<int>::iterator begin = m_usedStyles.begin();  compareStyle = \
m_styleManager->paragraphStyle(i);  for ( ; begin != m_usedStyles.end(); ++begin) {
-                    if (m_sourceModel->index(*begin, 0, QModelIndex()).internalId() \
!= -1) { //styleNone (internalId=-1) is a virtual style provided only for the UI. it \
                does not exist in KoStyleManager
-                        KoParagraphStyle *s = \
m_styleManager->paragraphStyle(m_sourceModel->index(*begin, 0, \
                QModelIndex()).internalId());
-                        if (KStringHandler::naturalCompare(compareStyle->name(), \
                s->name()) < 0) {
-                            break;
-                        }
+                    KoParagraphStyle *s = \
m_styleManager->paragraphStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId()); +                    if \
(KStringHandler::naturalCompare(compareStyle->name(), s->name()) < 0) { +             \
break;  }
                 }
                 m_usedStyles.insert(begin, \
m_sourceModel->indexForParagraphStyle(*compareStyle).row()); @@ -151,6 +222,19 @@ \
void DockerStylesComboModel::setStyleManager(KoStyleManager *sm)  createMapping();
 }
 
+void DockerStylesComboModel::setCurrentParagraphStyle(int styleId)
+{
+    if (!m_styleManager || !m_styleManager->paragraphStyle(styleId) || \
m_currentParagraphStyle == m_styleManager->paragraphStyle(styleId)) { +        \
return; //TODO do we create a default paragraphStyle? use the styleManager default? + \
} +    if (m_currentParagraphStyle) {
+        delete m_currentParagraphStyle;
+        m_currentParagraphStyle = 0;
+    }
+    m_currentParagraphStyle = m_styleManager->paragraphStyle(styleId)->clone();
+    m_currentParagraphStyle->setStyleId(-styleId);
+}
+
 void DockerStylesComboModel::styleApplied(const KoCharacterStyle *style)
 {
     if (!m_usedStylesId.contains(style->styleId())) {
@@ -158,11 +242,9 @@ void DockerStylesComboModel::styleApplied(const KoCharacterStyle \
                *style)
         if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
             QVector<int>::iterator begin = m_usedStyles.begin();
             for ( ; begin != m_usedStyles.end(); ++begin) {
-                if (m_sourceModel->index(*begin, 0, QModelIndex()).internalId() != \
-1) { //styleNone (internalId=-1) is a virtual style provided only for the UI. it \
                does not exist in KoStyleManager
-                    KoCharacterStyle *s = \
m_styleManager->characterStyle(m_sourceModel->index(*begin, 0, \
                QModelIndex()).internalId());
-                    if (KStringHandler::naturalCompare(style->name(), s->name()) < \
                0) {
-                        break;
-                    }
+                KoCharacterStyle *s = \
m_styleManager->characterStyle(m_sourceModel->index(*begin, 0, \
QModelIndex()).internalId()); +                if \
(KStringHandler::naturalCompare(style->name(), s->name()) < 0) { +                    \
break;  }
             }
             m_usedStyles.insert(begin, \
m_sourceModel->indexForCharacterStyle(*style).row()); @@ -194,16 +276,6 @@ void \
DockerStylesComboModel::createMapping()  m_sourceToProxy.clear();
     m_unusedStyles.clear();
 
-    //Handle the default characterStyle. If provided, the None virtual style is the \
                first style of the model. Its internalId is -1
-    if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
-        if (m_sourceModel->index(0, 0, QModelIndex()).isValid() && \
                m_sourceModel->index(0, 0, QModelIndex()).internalId() == -1) {
-            if (!m_usedStylesId.contains(-1)) {
-                m_usedStylesId.prepend(-1);
-                m_usedStyles.prepend(0);
-            }
-        }
-    }
-
     for (int i = 0; i < m_sourceModel->rowCount(QModelIndex()); ++i) {
         QModelIndex index = m_sourceModel->index(i, 0, QModelIndex());
         int id = (int)index.internalId();
@@ -246,8 +318,14 @@ void DockerStylesComboModel::createMapping()
             }
         }
     }
-    if (!m_usedStyles.isEmpty()) {
-        m_proxyToSource << UsedStyleId << m_usedStyles;
+    if (!m_usedStyles.isEmpty() || m_sourceModel->stylesType() == \
AbstractStylesModel::CharacterStyle) { +        m_proxyToSource << UsedStyleId;
+        if (m_sourceModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+            m_proxyToSource << CharacterStyleNoneId;
+        }
+        if (!m_usedStyles.isEmpty()) {
+            m_proxyToSource << m_usedStyles;
+        }
     }
     if (!m_unusedStyles.isEmpty()) {
         m_proxyToSource << UnusedStyleId << m_unusedStyles; //UsedStyleId and \
UnusedStyleId will be detected as title (in index method) and will be treated \
                accordingly
diff --git a/plugins/textshape/dialogs/DockerStylesComboModel.h \
b/plugins/textshape/dialogs/DockerStylesComboModel.h index 8c7d0dd..2287157 100644
--- a/plugins/textshape/dialogs/DockerStylesComboModel.h
+++ b/plugins/textshape/dialogs/DockerStylesComboModel.h
@@ -31,23 +31,43 @@ class DockerStylesComboModel : public StylesFilteredModelBase
     Q_OBJECT
 public:
 
-    enum CategoriesInternalIds {
+    enum DockerStylesComboInternalIds {
+        CharacterStyleNoneId = -1,
         UsedStyleId = -32000,
         UnusedStyleId = -32001
     };
 
     explicit DockerStylesComboModel(QObject *parent = 0);
 
+    ~DockerStylesComboModel();
+
+    /** ***************** Re-implement from QAbstractItemModel. */
+
     virtual Qt::ItemFlags flags(const QModelIndex &index) const;
 
     virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
 
     virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) \
const;  
+    /** ***************** Re-implement from the AbstractStylesModel */
+
+    virtual QModelIndex indexForCharacterStyle(const KoCharacterStyle &style) const;
+
+    virtual QImage stylePreview(const QModelIndex &index, QSize size);
+
+    /** ***************** Specific methods of the StylesFiltermodelBase */
+
+    virtual void setStylesModel(AbstractStylesModel *sourceModel);
+
+    /** Specific methods of the DockerStylesComboModel. */
+
     void setStyleManager(KoStyleManager *sm);
 
     void setInitialUsedStyles(QVector<int> usedStyles);
 
+    /** Specifies which paragraph style is currently the active one (on the current \
paragraph). This is used in order to properly preview the "As paragraph" virtual \
character style. */ +    void setCurrentParagraphStyle(int styleId);
+
 signals:
 
 public slots:
@@ -58,6 +78,8 @@ protected:
 
 private:
     KoStyleManager *m_styleManager;
+    KoParagraphStyle *m_currentParagraphStyle;
+    KoCharacterStyle *m_defaultCharacterStyle;
     QVector<int> m_usedStylesId;
     QVector<int> m_usedStyles;
     QVector<int> m_unusedStyles;
diff --git a/plugins/textshape/dialogs/FormattingPreview.cpp \
b/plugins/textshape/dialogs/FormattingPreview.cpp index 1ed3b83..1648649 100644
--- a/plugins/textshape/dialogs/FormattingPreview.cpp
+++ b/plugins/textshape/dialogs/FormattingPreview.cpp
@@ -84,6 +84,9 @@ void FormattingPreview::setText(const QString &sampleText)
 //Character properties
 void FormattingPreview::setCharacterStyle(const KoCharacterStyle* style)
 {
+    if (!style) {
+        return;
+    }
     if (m_characterStyle) {
         delete m_characterStyle;
     }
@@ -97,6 +100,9 @@ void FormattingPreview::setCharacterStyle(const KoCharacterStyle* \
style)  
 void FormattingPreview::setParagraphStyle(const KoParagraphStyle *style)
 {
+    if (!style) {
+        return;
+    }
     if (m_paragraphStyle) {
         delete m_paragraphStyle;
     }
@@ -120,7 +126,9 @@ void FormattingPreview::paintEvent(QPaintEvent *event)
     QRect rectang = contentsRect();
 
     p->fillRect(rectang, QBrush(QColor(Qt::white)));
-    p->drawImage(rectang, \
m_thumbnailer->thumbnail(m_characterStyle,m_paragraphStyle,rectang.size(),m_previewLayoutRequired, \
KoStyleThumbnailer::NoFlags)); +    if (m_characterStyle) {
+        p->drawImage(rectang, \
m_thumbnailer->thumbnail(m_characterStyle,m_paragraphStyle,rectang.size(),m_previewLayoutRequired, \
KoStyleThumbnailer::NoFlags)); +    }
 
     m_previewLayoutRequired = false;
 
diff --git a/plugins/textshape/dialogs/ParagraphGeneral.cpp \
b/plugins/textshape/dialogs/ParagraphGeneral.cpp index 23f3f0b..89b7bc4 100644
--- a/plugins/textshape/dialogs/ParagraphGeneral.cpp
+++ b/plugins/textshape/dialogs/ParagraphGeneral.cpp
@@ -132,7 +132,7 @@ void ParagraphGeneral::setStyle(KoParagraphStyle *style, int \
                level)
         CharacterGeneral::updateNextStyleCombo(m_styleManager->paragraphStyle(style->nextStyle()));
  KoParagraphStyle *parentStyle = style->parentStyle();
         if (parentStyle) {
-            widget.inheritStyle->setCurrentIndex(m_paragraphInheritedStyleModel->indexForParagraphStyle(*parentStyle).row());
 +            widget.inheritStyle->setCurrentItem(m_paragraphInheritedStyleModel->indexForParagraphStyle(*parentStyle));
                
             //m_paragraphInheritedStyleModel->setCurrentParagraphStyle(parentStyle->styleId());
  }
     }
diff --git a/plugins/textshape/dialogs/SimpleCharacterWidget.cpp \
b/plugins/textshape/dialogs/SimpleCharacterWidget.cpp index 0e3b01d..c2ffc05 100644
--- a/plugins/textshape/dialogs/SimpleCharacterWidget.cpp
+++ b/plugins/textshape/dialogs/SimpleCharacterWidget.cpp
@@ -38,6 +38,7 @@
 #include <KoStyleManager.h>
 
 #include <KDebug>
+#include <KoTextDebug.h>
 
 #include <QTextLayout>
 #include <QComboBox>
@@ -93,6 +94,7 @@ SimpleCharacterWidget::SimpleCharacterWidget(TextTool *tool, \
QWidget *parent)  widget.fontsFrame->setColumnStretch(0,1);
 
     m_stylesModel->setStyleThumbnailer(m_thumbnailer);
+    m_sortedStylesModel->setStyleThumbnailer(m_thumbnailer);
     widget.characterStyleCombo->setStylesModel(m_sortedStylesModel);
     connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
                SLOT(styleSelected(QModelIndex&)));
     connect(widget.characterStyleCombo, SIGNAL(newStyleRequested(QString)), this, \
SIGNAL(newStyleRequested(QString))); @@ -166,8 +168,9 @@ void \
SimpleCharacterWidget::setCurrentFormat(const QTextCharFormat& format, cons  }
         }
         disconnect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
                SLOT(styleSelected(QModelIndex&)));
-         //TODO, this is very brittle index 1 is because index 0 is the title. The \
proper solution to that would be for the "None" style to have a styleId which does \
                not get applied on the text, but can be used in the ui
-        widget.characterStyleCombo->setCurrentIndex((useParagraphStyle)?1:m_sortedStylesModel->indexForCharacterStyle(*style).row());
 +        //if the comparison style was the paragraph style. Send a null style, the \
DockerStylesComboModel will return an index for the None character style +        \
style = (useParagraphStyle?0:style); +        \
widget.characterStyleCombo->setCurrentItem(m_sortedStylesModel->indexForCharacterStyle(*style));
  widget.characterStyleCombo->setStyleIsOriginal(unchanged);
         widget.characterStyleCombo->slotUpdatePreview();
         connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&))); @@ -221,6 +224,7 @@ void \
SimpleCharacterWidget::setCurrentBlockFormat(const QTextBlockFormat &format  \
m_currentBlockFormat = format;  
     m_stylesModel->setCurrentParagraphStyle(format.intProperty(KoParagraphStyle::StyleId));
 +    m_sortedStylesModel->setCurrentParagraphStyle(format.intProperty(KoParagraphStyle::StyleId));
                
     disconnect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&)));  widget.characterStyleCombo->slotUpdatePreview();
     connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
                SLOT(styleSelected(QModelIndex&)));
diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp \
b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp index c01cea5..ae7308e 100644
--- a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp
+++ b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp
@@ -280,9 +280,10 @@ void SimpleParagraphWidget::setCurrentFormat(const \
QTextBlockFormat &format)  //we are updating the combo's selected item to what is the \
current format. we do not want this to apply the style as it would mess up the undo \
                stack, the change tracking,...
         disconnect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&)));  m_sortedStylesModel->styleApplied(style);
-        widget.paragraphStyleCombo->setCurrentIndex(m_sortedStylesModel->indexForParagraphStyle(*style).row());
                
-        widget.paragraphStyleCombo->setStyleIsOriginal(unchanged);
+        m_sortedStylesModel->setCurrentParagraphStyle(id);
         m_stylesModel->setCurrentParagraphStyle(id);
+        widget.paragraphStyleCombo->setCurrentItem(m_sortedStylesModel->indexForParagraphStyle(*style));
 +        widget.paragraphStyleCombo->setStyleIsOriginal(unchanged);
         widget.paragraphStyleCombo->slotUpdatePreview();
         connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&)));  }
diff --git a/plugins/textshape/dialogs/StyleManager.cpp \
b/plugins/textshape/dialogs/StyleManager.cpp index c561d35..c15c58d 100644
--- a/plugins/textshape/dialogs/StyleManager.cpp
+++ b/plugins/textshape/dialogs/StyleManager.cpp
@@ -64,7 +64,6 @@ StyleManager::StyleManager(QWidget *parent)
 
     m_paragraphStylesModel->setStyleThumbnailer(m_thumbnailer);
     m_characterStylesModel->setStyleThumbnailer(m_thumbnailer);
-    m_characterStylesModel->setProvideStyleNone(false);
     widget.paragraphStylesListView->setModel(m_paragraphStylesModel);
     widget.characterStylesListView->setModel(m_characterStylesModel);
 
diff --git a/plugins/textshape/dialogs/StylesCombo.cpp \
b/plugins/textshape/dialogs/StylesCombo.cpp index 4296ce1..2e7e76b 100644
--- a/plugins/textshape/dialogs/StylesCombo.cpp
+++ b/plugins/textshape/dialogs/StylesCombo.cpp
@@ -62,8 +62,6 @@ StylesCombo::StylesCombo(QWidget *parent)
     connect(delegate, SIGNAL(clickedInItem(QModelIndex)), this, \
SLOT(slotItemClicked(QModelIndex)));  setItemDelegate(delegate);
 
-//    connect(this, SIGNAL(currentIndexChanged(int)), this, \
                SLOT(slotSelectionChanged(int)));
-
     QComboBox::setEditable(true);
     setIconSize(QSize(0,0));
 
@@ -130,22 +128,21 @@ void StylesCombo::setLineEdit(QLineEdit *edit)
 
 }
 
-void StylesCombo::slotSelectionChanged(int index)
+void StylesCombo::setCurrentItem(const QModelIndex &index)
 {
-    m_selectedItem = index;
-    m_preview->setPreview(m_stylesModel->stylePreview(index, \
                m_preview->availableSize()));
-    update();
-//    emit selectionChanged(index);
+    m_currentIndex = index;
+    blockSignals(true);
+    setCurrentIndex(index.row());
+    slotUpdatePreview();
+    blockSignals(false);
 }
 
 void StylesCombo::slotItemClicked(QModelIndex index)
 {
     //this slot allows us to emit a selected signal. There is a bit of redundancy if \
the item clicked was indeed a new selection, where we also emit the selectionChanged \
signal from the slot above.  m_selectedItem = index.row();
-    m_preview->setPreview(m_stylesModel->stylePreview(m_selectedItem, \
                m_preview->availableSize()));
-    m_currentIndex = index;
-    update();
-    emit selected(m_selectedItem);
+    setCurrentItem(index);
+    emit selected(m_selectedItem); //TODO: remove this when the styleManager dialog \
is redone  emit selected(index);
     hidePopup(); //the editor event has accepted the mouseReleased event. Call \
hidePopup ourselves then.  }
@@ -155,7 +152,7 @@ void StylesCombo::slotUpdatePreview()
     if (!m_stylesModel) {
         return;
     }
-    m_preview->setPreview(m_stylesModel->stylePreview(currentIndex(), \
m_preview->availableSize())); +    \
m_preview->setPreview(m_stylesModel->stylePreview(m_currentIndex, \
m_preview->availableSize()));  update();
 }
 
diff --git a/plugins/textshape/dialogs/StylesCombo.h \
b/plugins/textshape/dialogs/StylesCombo.h index d6ce959..c6f7d9c 100644
--- a/plugins/textshape/dialogs/StylesCombo.h
+++ b/plugins/textshape/dialogs/StylesCombo.h
@@ -61,6 +61,9 @@ public slots:
     /** This slot needs to be called if the preview in the main area needs to be \
updated for some reason */  void slotUpdatePreview();
 
+    /** Set the current item of the combo (equivalent of the \
QComboBox::setCurrentIndex(int row) */ +    void setCurrentItem(const QModelIndex \
&index); +
 signals:
     /** This is emitted when a selection is made (programatically or by user \
                interaction). It is
       * to be noted that this signal is also emitted when an item is selected again.
@@ -90,7 +93,6 @@ signals:
 private slots:
     void slotDeleteStyle(QModelIndex);
     void slotShowDia(QModelIndex);
-    void slotSelectionChanged(int index);
     void slotItemClicked(QModelIndex);
     void slotPreviewClicked();
     void slotModelReset();
diff --git a/plugins/textshape/dialogs/StylesFilteredModelBase.cpp \
b/plugins/textshape/dialogs/StylesFilteredModelBase.cpp index f84df16..0c81257 100644
--- a/plugins/textshape/dialogs/StylesFilteredModelBase.cpp
+++ b/plugins/textshape/dialogs/StylesFilteredModelBase.cpp
@@ -94,7 +94,7 @@ Qt::ItemFlags StylesFilteredModelBase::flags(const QModelIndex \
&index) const  
 void StylesFilteredModelBase::setStyleThumbnailer(KoStyleThumbnailer *thumbnailer)
 {
-    Q_UNUSED(thumbnailer);
+    m_styleThumbnailer = thumbnailer;
 }
 
 QModelIndex StylesFilteredModelBase::indexForParagraphStyle(const KoParagraphStyle \
&style) const @@ -104,8 +104,7 @@ QModelIndex \
                StylesFilteredModelBase::indexForParagraphStyle(const KoParagraphSty
     if (!sourceIndex.isValid() || (m_sourceToProxy.at(sourceIndex.row()) < 0)) {
         return QModelIndex();
     }
-
-    return createIndex(m_sourceToProxy.at(sourceIndex.row()), 0, style.styleId());
+    return createIndex(m_sourceToProxy.at(sourceIndex.row()), 0, \
int(sourceIndex.internalId()));  }
 
 QModelIndex StylesFilteredModelBase::indexForCharacterStyle(const KoCharacterStyle \
&style) const @@ -115,27 +114,17 @@ QModelIndex \
                StylesFilteredModelBase::indexForCharacterStyle(const KoCharacterSty
     if (!sourceIndex.isValid() || m_sourceToProxy.at(sourceIndex.row()) < 0) {
         return QModelIndex();
     }
-    return createIndex(m_sourceToProxy.at(sourceIndex.row()), 0, style.styleId());
+    return createIndex(m_sourceToProxy.at(sourceIndex.row()), 0, \
int(sourceIndex.internalId()));  }
 
-QImage StylesFilteredModelBase::stylePreview(int row, QSize size)
-{
-    if (row < 0) {
-        return QImage();
-    }
-    return m_sourceModel->stylePreview(m_proxyToSource.at(row), size);
-
-}
-/*
-QImage StylesFilteredModelBase::stylePreview(QModelIndex &index, QSize size)
+QImage StylesFilteredModelBase::stylePreview(const QModelIndex &index, QSize size)
 {
     if (!index.isValid()) {
         return QImage();
     }
-    return m_sourceModel->stylePreview(index, size); //TODO be carefull there. this \
is assuming the sourceModel is only using the internalId, and the index's internalId \
                matches the model's
-
+    return m_sourceModel->stylePreview(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0), size);  }
-*/
+
 void StylesFilteredModelBase::setStylesModel(AbstractStylesModel *sourceModel)
 {
     if (m_sourceModel == sourceModel) {
diff --git a/plugins/textshape/dialogs/StylesFilteredModelBase.h \
b/plugins/textshape/dialogs/StylesFilteredModelBase.h index b39a5fa..402d5ed 100644
--- a/plugins/textshape/dialogs/StylesFilteredModelBase.h
+++ b/plugins/textshape/dialogs/StylesFilteredModelBase.h
@@ -42,7 +42,7 @@ class StylesFilteredModelBase : public AbstractStylesModel
 public:
     explicit StylesFilteredModelBase(QObject *parent = 0);
 
-    /** Re-implement from QAbstractItemModel. */
+    /** ***************** Re-implement from QAbstractItemModel. */
 
     virtual QModelIndex index(int row, int column=0, const QModelIndex &parent = \
QModelIndex()) const;  
@@ -56,7 +56,7 @@ public:
 
     virtual Qt::ItemFlags flags(const QModelIndex &index) const;
 
-    /** Specific methods of the AbstractStylesModel */
+    /** ***************** Specific methods of the AbstractStylesModel */
 
     /** Sets the @class KoStyleThumbnailer of the model. It is required that a \
@param thumbnailer is set before using the model. */  virtual void \
setStyleThumbnailer(KoStyleThumbnailer *thumbnailer); @@ -67,19 +67,18 @@ public:
     /** Return a @class QModelIndex for the specified @param style. */
     virtual QModelIndex indexForCharacterStyle(const KoCharacterStyle &style) const;
 
-    /** Returns a QImage which is a preview of the style specified by @param row of \
the given @param size. +    /** Returns a QImage which is a preview of the style \
                specified by @param index of the given @param size.
       * If size isn't specified, the default size of the given @class \
                KoStyleThumbnailer is used.
     */
-    virtual QImage stylePreview(int row, QSize size = QSize());
-//    virtual QImage stylePreview(QModelIndex &index, QSize size = QSize());
+    virtual QImage stylePreview(const QModelIndex &index, QSize size = QSize());
 
     virtual AbstractStylesModel::Type stylesType() const;
 
-    /** Specific methods of the StylesFiltermodelBase */
+    /** ***************** Specific methods of the StylesFiltermodelBase */
 
     /** Sets the sourceModel. Setting the model will trigger the mapping.
      */
-    void setStylesModel(AbstractStylesModel *sourceModel);
+    virtual void setStylesModel(AbstractStylesModel *sourceModel);
 
 protected slots:
     void modelAboutToBeReset();
diff --git a/plugins/textshape/dialogs/StylesModel.cpp \
b/plugins/textshape/dialogs/StylesModel.cpp index 2ac95fa..a264855 100644
--- a/plugins/textshape/dialogs/StylesModel.cpp
+++ b/plugins/textshape/dialogs/StylesModel.cpp
@@ -50,8 +50,6 @@ StylesModel::StylesModel(KoStyleManager *manager, \
AbstractStylesModel::Type mode  m_defaultCharacterStyle->setStyleId(-1);
         m_defaultCharacterStyle->setName(i18n("None"));
         m_defaultCharacterStyle->setFontPointSize(12);
-
-        m_provideStyleNone = true;
     }
 
     connect(m_styleMapper, SIGNAL(mapped(int)), this, SLOT(updateName(int)));
@@ -112,33 +110,20 @@ QVariant StylesModel::data(const QModelIndex &index, int role) \
const  if (m_modelType == StylesModel::ParagraphStyle) {
             KoParagraphStyle *paragStyle = m_styleManager->paragraphStyle(id);
             if (paragStyle) {
-                return m_styleThumbnailer->thumbnail(paragStyle);
+                return m_styleThumbnailer->thumbnail(paragStyle, data(index, \
Qt::SizeHintRole).toSize());  }
             if (!paragStyle && m_draftParStyleList.contains(id)) {
-                return m_styleThumbnailer->thumbnail(m_draftParStyleList[id]);
+                return m_styleThumbnailer->thumbnail(m_draftParStyleList[id], \
data(index, Qt::SizeHintRole).toSize());  }
         }
         else {
             KoCharacterStyle *usedStyle = 0;
-            if (id == -1) {
-                usedStyle = static_cast<KoCharacterStyle*>(m_currentParagraphStyle);
-                if (!usedStyle) {
-                    usedStyle = m_defaultCharacterStyle;
-                }
-                usedStyle->setName(i18n("None"));
-                if (usedStyle->styleId() >= 0) { //if the styleId is -1, we are \
                using the default character style
-                    usedStyle->setStyleId(-usedStyle->styleId()); //this style is \
not managed by the styleManager but its styleId will be used in the thumbnail cache \
                as part of the key.
-                }
-                return m_styleThumbnailer->thumbnail(usedStyle);
+            usedStyle = m_styleManager->characterStyle(id);
+            if (usedStyle) {
+                return m_styleThumbnailer->thumbnail(usedStyle, \
m_currentParagraphStyle, data(index, Qt::SizeHintRole).toSize());  }
-            else {
-                usedStyle = m_styleManager->characterStyle(id);
-                if (usedStyle) {
-                    return m_styleThumbnailer->thumbnail(usedStyle, \
                m_currentParagraphStyle);
-                }
-                if (!usedStyle && m_draftCharStyleList.contains(id)) {
-                    return m_styleThumbnailer->thumbnail(m_draftCharStyleList[id]);
-                }
+            if (!usedStyle && m_draftCharStyleList.contains(id)) {
+                return m_styleThumbnailer->thumbnail(m_draftCharStyleList[id], \
m_currentParagraphStyle, data(index, Qt::SizeHintRole).toSize());  }
         }
         break;
@@ -170,13 +155,6 @@ void StylesModel::setCurrentParagraphStyle(int styleId)
     m_currentParagraphStyle = m_styleManager->paragraphStyle(styleId)->clone();
 }
 
-void StylesModel::setProvideStyleNone(bool provide)
-{
-    if (m_modelType == StylesModel::CharacterStyle) {
-        m_provideStyleNone = provide;
-    }
-}
-
 QModelIndex StylesModel::indexForParagraphStyle(const KoParagraphStyle &style) const
 {
     if (&style) {
@@ -193,53 +171,10 @@ QModelIndex StylesModel::indexForCharacterStyle(const \
KoCharacterStyle &style) c  if (&style) {
         return createIndex(m_styleList.indexOf(style.styleId()), 0, \
style.styleId());  }
-    else {
-        return QModelIndex();
-    }
+    return QModelIndex();
 }
 
-QImage StylesModel::stylePreview(int row, QSize size)
-{
-    if (!m_styleManager || !m_styleThumbnailer) {
-        return QImage();
-    }
-    if (m_modelType == StylesModel::ParagraphStyle) {
-        KoParagraphStyle *usedStyle = 0;
-        usedStyle = m_styleManager->paragraphStyle(index(row).internalId());
-        if (usedStyle) {
-            return m_styleThumbnailer->thumbnail(usedStyle, size);
-        }
-        if (!usedStyle && m_draftParStyleList.contains(index(row).internalId())) {
-            return m_styleThumbnailer->thumbnail(m_draftParStyleList[index(row).internalId()], \
                size);
-        }
-    }
-    else {
-        KoCharacterStyle *usedStyle = 0;
-        if (index(row).internalId() == -1) {
-            usedStyle = static_cast<KoCharacterStyle*>(m_currentParagraphStyle);
-            if (!usedStyle) {
-                usedStyle = m_defaultCharacterStyle;
-            }
-            usedStyle->setName(i18n("None"));
-            if (usedStyle->styleId() >= 0) {
-                usedStyle->setStyleId(-usedStyle->styleId()); //this style is not \
managed by the styleManager but its styleId will be used in the thumbnail cache as \
                part of the key.
-            }
-            return m_styleThumbnailer->thumbnail(usedStyle, m_currentParagraphStyle, \
                size);
-        }
-        else {
-            usedStyle = m_styleManager->characterStyle(index(row).internalId());
-            if (usedStyle) {
-                return m_styleThumbnailer->thumbnail(usedStyle, \
                m_currentParagraphStyle, size);
-            }
-            if (!usedStyle && \
                m_draftCharStyleList.contains(index(row).internalId())) {
-                return \
m_styleThumbnailer->thumbnail(m_draftCharStyleList[index(row).internalId()],m_currentParagraphStyle, \
                size);
-            }
-        }
-    }
-    return QImage();
-}
-/*
-QImage StylesModel::stylePreview(QModelIndex &index, QSize size)
+QImage StylesModel::stylePreview(const QModelIndex &index, QSize size)
 {
     if (!m_styleManager || !m_styleThumbnailer) {
         return QImage();
@@ -256,30 +191,17 @@ QImage StylesModel::stylePreview(QModelIndex &index, QSize \
size)  }
     else {
         KoCharacterStyle *usedStyle = 0;
-        if (index.internalId() == -1) {
-            usedStyle = static_cast<KoCharacterStyle*>(m_currentParagraphStyle);
-            if (!usedStyle) {
-                usedStyle = m_defaultCharacterStyle;
-            }
-            usedStyle->setName(i18n("None"));
-            if (usedStyle->styleId() >= 0) {
-                usedStyle->setStyleId(-usedStyle->styleId()); //this style is not \
managed by the styleManager but its styleId will be used in the thumbnail cache as \
                part of the key.
-            }
+        usedStyle = m_styleManager->characterStyle(index.internalId());
+        if (usedStyle) {
             return m_styleThumbnailer->thumbnail(usedStyle, m_currentParagraphStyle, \
size);  }
-        else {
-            usedStyle = m_styleManager->characterStyle(index.internalId());
-            if (usedStyle) {
-                return m_styleThumbnailer->thumbnail(usedStyle, \
                m_currentParagraphStyle, size);
-            }
-            if (!usedStyle && m_draftCharStyleList.contains(index.internalId())) {
-                return \
m_styleThumbnailer->thumbnail(m_draftCharStyleList[index.internalId()],m_currentParagraphStyle, \
                size);
-            }
+        if (!usedStyle && m_draftCharStyleList.contains(index.internalId())) {
+            return m_styleThumbnailer->thumbnail(m_draftCharStyleList[index.internalId()],m_currentParagraphStyle, \
size);  }
     }
     return QImage();
 }
-*/
+
 void StylesModel::setStyleManager(KoStyleManager *sm)
 {
     if (sm == m_styleManager)
@@ -370,11 +292,6 @@ void StylesModel::addCharacterStyle(KoCharacterStyle *style)
     // find the place where we need to insert the style
     QList<int>::iterator begin = m_styleList.begin();
     int index = 0;
-    // the None style should also be the first one so only start after it
-    if (begin != m_styleList.end() && *begin == -1) {
-        ++begin;
-        ++index;
-    }
     for ( ; begin != m_styleList.end(); ++begin) {
         KoCharacterStyle *s = m_styleManager->characterStyle(*begin);;
         if (!s && m_draftCharStyleList.contains(*begin))
@@ -407,10 +324,6 @@ void StylesModel::updateCharacterStyles()
     beginResetModel();
     m_styleList.clear();
 
-    if (m_provideStyleNone && m_styleManager->paragraphStyles().count()) {
-        m_styleList.append(-1);
-    }
-
     QList<KoCharacterStyle *> styles = m_styleManager->characterStyles();
     qSort(styles.begin(), styles.end(), sortCharacterStyleByName);
 
@@ -494,10 +407,6 @@ void StylesModel::updateName(int styleId)
                 m_styleThumbnailer->removeFromCache(characterStyle);
 
                 QList<int>::iterator begin = m_styleList.begin();
-                if (begin != m_styleList.end() && *begin == -1) {
-                    ++begin;
-                    ++newIndex;
-                }
                 for ( ; begin != m_styleList.end(); ++begin) {
                     // don't test again the same style
                     if (*begin == styleId) {
diff --git a/plugins/textshape/dialogs/StylesModel.h \
b/plugins/textshape/dialogs/StylesModel.h index cd8117a..d078b5f 100644
--- a/plugins/textshape/dialogs/StylesModel.h
+++ b/plugins/textshape/dialogs/StylesModel.h
@@ -76,15 +76,6 @@ public:
     /** ************************* */
     /** Initialising of the model */
 
-    /** Specify if the combo should provide the virtual style None. This style is a \
                virtual style which equates to no style. It is only relevant for \
                character styles.
-        In case the "None" character style is selected, the character formatting \
                properties of the paragraph style are used.
-        A @class StylesModel of the @enum Type ParagraphStyle always has this \
                property set to false.
-        On the other hand, the default for a @class StylesModel of the @enum Type \
                CharacterStyle is true.
-
-        It is important to set this before setting the stylemanager on the model. \
                The flag is used when populating the styles from the KoStyleManager.
-    */
-    void setProvideStyleNone(bool provide);
-
     /** Sets the @class KoStyleManager of the model. Setting this will populate the \
                styles. It is required that a @param manager is set before using the \
                model.
       * CAUTION: Populating the style will select the first inserted item. If this \
model is already set on a view, this might cause the view to emit an item selection \
                changed signal.
     */
@@ -103,11 +94,10 @@ public:
     /** Return a @class QModelIndex for the specified @param style. */
     QModelIndex indexForCharacterStyle(const KoCharacterStyle &style) const;
 
-    /** Returns a QImage which is a preview of the style specified by @param row of \
the given @param size. +    /** Returns a QImage which is a preview of the style \
                specified by @param index of the given @param size.
       * If size isn't specified, the default size of the given @class \
                KoStyleThumbnailer is used.
     */
-    QImage stylePreview(int row, QSize size = QSize());
-//    QImage stylePreview(QModelIndex &index, QSize size = QSize());
+    QImage stylePreview(const QModelIndex &index, QSize size = QSize());
 
     /** Specifies which paragraph style is currently the active one (on the current \
paragraph). This is used in order to properly preview the "As paragraph" virtual \
character style. */  void setCurrentParagraphStyle(int styleId);
diff --git a/words/templates/Wordprocessing/A4.odt \
b/words/templates/Wordprocessing/A4.odt index 03a8595..67ee171 100644
Binary files a/words/templates/Wordprocessing/A4.odt and \
b/words/templates/Wordprocessing/A4.odt differ


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic