From kde-commits Tue Jan 01 16:11:19 2013 From: Pierre Stirnweiss Date: Tue, 01 Jan 2013 16:11:19 +0000 To: kde-commits Subject: [calligra] plugins/textshape/dialogs: Merge branch textshape-stylesWidget-PierreSt into master Message-Id: <20130101161119.09301A6091 () git ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=135705669005799 Git commit ea4acc2dcf74fbc92d1fc6743f13f953c26cf508 by Pierre Stirnweiss. Committed on 01/01/2013 at 14:40. Pushed by pstirnweiss into branch 'master'. Merge branch textshape-stylesWidget-PierreSt into master The stylesCombo should now display the styles sorted per usage with a category title. There are also several bug fixes for the usage sorted combo list. REVIEW: 108060 Squashed commit of the following: commit ee16d3673044796823e974def00b6e98b355a75e Merge: 966ad6d 10b83ff Author: Pierre Stirnweiss Date: Tue Jan 1 14:28:33 2013 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 966ad6d03ee3973ec46642429fb6d4f3706c9b75 Author: Pierre Stirnweiss Date: Tue Jan 1 14:17:24 2013 +0100 Fix paragraph style is applied twice regression. The paragraph style was applied twice because an old style signal was still used. commit f4cabe5f51a119f931b2ff4832548c1f78f1087f Merge: 5716300 cfb0253 Author: Pierre Stirnweiss Date: Tue Jan 1 09:29:03 2013 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 5716300a666bb75c68247d8d114e3ee25638a626 Author: Pierre Stirnweiss Date: Mon Dec 31 17:43:33 2012 +0100 Correct logic of previous patch commit 754306ae1c4ea4c7149be085da401860226f54e6 Merge: d968f8a 0260a75 Author: Pierre Stirnweiss Date: Mon Dec 31 17:05:27 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit d968f8a2126c29e1b62b0c1af60c5700626a1584 Author: Pierre Stirnweiss Date: Mon Dec 31 17:01:26 2012 +0100 Remove default paragraph style from user visible lists. The default paragraph style was seen in user visible lists (as blank item). This style is not supposed to be user visible/selectable. commit 3dadacea3d654738bb88d4a416c008611b0f5149 Merge: 7ea974a bec31b8 Author: Pierre Stirnweiss Date: Sun Dec 30 11:37:21 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 7ea974af2415e3c4aa4ed6f4f2ce1c02f1e20b38 Author: Pierre Stirnweiss Date: Sun Dec 30 10:28:29 2012 +0100 Fix sorting of style names. The style names were not sorted in natural order. Use KStringHandler::naturalCompare to fix the problem. The sorting of styles per category (ie. list styles,...) belongs to a wish item, and needs debating first. BUG: 288651 REVIEW: 108020 commit cf59966417599a3de4b05a1470a6854ed358a2b6 Merge: 4c76a36 a23f73c Author: Pierre Stirnweiss Date: Fri Dec 28 21:32:57 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 4c76a36083877e1a736bf5bbe3386cc6a9f4c150 Author: Pierre Stirnweiss Date: Fri Dec 28 21:28:16 2012 +0100 Keep the proper style selection after a style moves from unused to used The view gets notified when the model is changed on moving a style from unused to used. commit c43723909a9e32b5aa03786c46364d94ff3b9d4a Author: Pierre Stirnweiss Date: Sun Dec 23 19:46:42 2012 +0100 Fix apply characterStyle to caret without selection REVIEW: 107878 commit 82c8d538979b6b5c7cb90c2a374cea49bdfc66a0 Merge: 4b81bbb 7deaf57 Author: Pierre Stirnweiss Date: Sun Dec 23 14:15:57 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 4b81bbb44e2a2e662069dcf8264ef88a1825a9ab Author: Pierre Stirnweiss Date: Sun Dec 23 13:31:02 2012 +0100 Fix clicking in a selection does not update the caret. Initialize m_drag in the TextTool solves the problem somehow. REVIEW: 107849 commit 23e7859fcdf7c9151d6767648e1a57bb8e726276 Merge: ab191fb 82b661c Author: Pierre Stirnweiss Date: Sun Dec 16 14:48:26 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit ab191fb238011a53af4867231422de3e61c3f89e Author: Pierre Stirnweiss Date: Sun Dec 16 14:46:54 2012 +0100 tempo commit 7e8816f0121afebd5ab538d1e00cc87baca0e423 Author: Pierre Stirnweiss Date: Mon Dec 10 21:35:27 2012 +0100 Initial steps at implementing category titles in the stylesCombo commit fb0ff739d1c49b63a00a5f4d7e8e903b6c8c03b2 Merge: e8e9407 48ac948 Author: Pierre Stirnweiss Date: Mon Dec 10 17:57:55 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit e8e9407c088577aff79e28cd2262c0f02c29cbc7 Author: Pierre Stirnweiss Date: Sat Dec 1 14:07:50 2012 +0100 Clean up commit 4a31b7e1fe79fbd959cadbcaeb33bafe115f6d6e Merge: 677be5e fc4b005 Author: Pierre Stirnweiss Date: Sat Dec 1 13:54:43 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 677be5ea17fa68da4cd171ec5d0a5a7f1be87556 Author: Pierre Stirnweiss Date: Sat Dec 1 13:21:13 2012 +0100 Fix next style appears as modified after a list style commit 31cdb8e0ad6ee2ea0a42894933a2db48c543aab1 Merge: bd699d1 f3ae109 Author: Pierre Stirnweiss Date: Wed Nov 28 18:28:01 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit bd699d1bbf8c837505ebe19c5c0fc7cbc307ca11 Merge: 15e1a5c c98e784 Author: Pierre Stirnweiss Date: Tue Nov 27 20:14:12 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 15e1a5c348a09e516fa5b3e58525e9f4440060a1 Author: Pierre Stirnweiss Date: Tue Nov 27 17:58:17 2012 +0100 Fix problems highlighted by C. Boemann commit fe4de0d618eb6c6dd83ab07f8641f6e24cfd55fc Author: Pierre Stirnweiss Date: Mon Nov 26 18:43:33 2012 +0100 Clean-up left-over commit 1e40dfdc986eb2bc9114684a20aa5ec60db77d2d Merge: ea8cdb0 82cc058 Author: Pierre Stirnweiss Date: Sun Nov 25 10:19:14 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit ea8cdb0e14e6805b4082ffd0929c8b1b344c82f4 Author: Pierre Stirnweiss Date: Sat Nov 24 15:02:15 2012 +0100 Additional clean ups commit 6308ed4fd70aa99ccd5214806f370423ca5b7015 Merge: d306e00 81b50ca Author: Pierre Stirnweiss Date: Sat Nov 24 14:49:45 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit d306e009525c97d2c7e1706a47ec267d7e994c8c Author: Pierre Stirnweiss Date: Sat Nov 24 14:48:09 2012 +0100 Clean ups in the code commit 231e717b0c1c7dbec984679e0fb07dc821f8e889 Author: Pierre Stirnweiss Date: Sun Nov 11 13:03:26 2012 +0100 Fix another crash commit c37b513c5b4f9c09345848f2885f4eac24791008 Author: Pierre Stirnweiss Date: Sun Nov 11 12:42:08 2012 +0100 Fix random crash. commit 0a9c5e3464c39e45eeeb26b1c65643bdb63fca32 Merge: 8e675f4 e6c1c31 Author: Pierre Stirnweiss Date: Sat Nov 10 17:07:22 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit 8e675f4d1b66eda355e994c0c88b6ac67337bca3 Merge: bcb9fbd 6c7d9e1 Author: Pierre Stirnweiss Date: Sat Nov 10 15:54:06 2012 +0100 Merge branch 'master' into textshape-stylesWidget-PierreSt commit bcb9fbd767aa2c4b7e5670ab2546797e9cf3e42b Author: Pierre Stirnweiss Date: Sat Nov 10 15:52:53 2012 +0100 Initial population of style, a tad further. commit fbbcf132764ca9a60b59e46aa844df918aa8fd05 Author: Pierre Stirnweiss Date: Mon Oct 22 21:36:20 2012 +0200 Add missing bits to previous commit commit 889e39862888ef83dc052604746611c959352bf0 Author: Pierre Stirnweiss Date: Sun Oct 21 23:39:14 2012 +0200 Create filter for stylesCombo in the docker M +1 -0 plugins/textshape/dialogs/AbstractStylesModel.h M +65 -3 plugins/textshape/dialogs/DockerStylesComboModel.cpp M +12 -0 plugins/textshape/dialogs/DockerStylesComboModel.h M +24 -10 plugins/textshape/dialogs/SimpleCharacterWidget.cpp M +1 -0 plugins/textshape/dialogs/SimpleCharacterWidget.h M +19 -9 plugins/textshape/dialogs/SimpleParagraphWidget.cpp M +1 -0 plugins/textshape/dialogs/SimpleParagraphWidget.h M +9 -1 plugins/textshape/dialogs/StylesCombo.cpp M +3 -0 plugins/textshape/dialogs/StylesCombo.h M +127 -36 plugins/textshape/dialogs/StylesDelegate.cpp M +11 -0 plugins/textshape/dialogs/StylesFilteredModelBase.cpp M +1 -0 plugins/textshape/dialogs/StylesFilteredModelBase.h M +44 -1 plugins/textshape/dialogs/StylesModel.cpp M +1 -0 plugins/textshape/dialogs/StylesModel.h http://commits.kde.org/calligra/ea4acc2dcf74fbc92d1fc6743f13f953c26cf508 diff --git a/plugins/textshape/dialogs/AbstractStylesModel.h b/plugins/text= shape/dialogs/AbstractStylesModel.h index 6fddd0e..5ff2d56 100644 --- a/plugins/textshape/dialogs/AbstractStylesModel.h +++ b/plugins/textshape/dialogs/AbstractStylesModel.h @@ -86,6 +86,7 @@ public: * If size isn't specified, the default size of the given @class KoSt= yleThumbnailer is used. */ virtual QImage stylePreview(int row, QSize size =3D QSize()) =3D 0; +// virtual QImage stylePreview(QModelIndex &index, QSize size =3D QSize= ()) =3D 0; = /** Returns the type of styles in the model */ virtual AbstractStylesModel::Type stylesType() const =3D 0; diff --git a/plugins/textshape/dialogs/DockerStylesComboModel.cpp b/plugins= /textshape/dialogs/DockerStylesComboModel.cpp index be83819..a669b77 100644 --- a/plugins/textshape/dialogs/DockerStylesComboModel.cpp +++ b/plugins/textshape/dialogs/DockerStylesComboModel.cpp @@ -34,6 +34,60 @@ DockerStylesComboModel::DockerStylesComboModel(QObject *= parent) : { } = +Qt::ItemFlags DockerStylesComboModel::flags(const QModelIndex &index) const +{ + if (index.internalId() =3D=3D UsedStyleId || index.internalId() =3D=3D= UnusedStyleId) { + return (Qt::NoItemFlags); + } + return (Qt::ItemIsEnabled | Qt::ItemIsSelectable); +} + +QModelIndex DockerStylesComboModel::index(int row, int column, const QMode= lIndex &parent) const +{ + if (row < 0 || column !=3D 0) + return QModelIndex(); + + if (!parent.isValid()) { + if (row >=3D m_proxyToSource.count()) { + return QModelIndex(); + } + return createIndex(row, column, (m_proxyToSource.at(row) >=3D 0)?i= nt(m_sourceModel->index(m_proxyToSource.at(row), 0, QModelIndex()).internal= Id()):m_proxyToSource.at(row)); + } + return QModelIndex(); +} + +QVariant DockerStylesComboModel::data(const QModelIndex &index, int role) = const +{ + if (!index.isValid()) + return QVariant(); + + switch (role){ + case AbstractStylesModel::isTitleRole: { + if (index.internalId() =3D=3D UsedStyleId || index.internalId() = =3D=3D UnusedStyleId) { + return true; + } + } + case Qt::DisplayRole: { + if (index.internalId() =3D=3D UsedStyleId) { + return i18n("Used Styles"); + } + if (index.internalId() =3D=3D UnusedStyleId) { + return i18n("Unused Styles"); + } + return QVariant(); + } + case Qt::DecorationRole: { + return m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at= (index.row()), 0, QModelIndex()), role); + break; + } + case Qt::SizeHintRole: { + return QVariant(QSize(250, 48)); + } + default: break; + }; + return QVariant(); +} + void DockerStylesComboModel::setInitialUsedStyles(QVector usedStyles) { Q_UNUSED(usedStyles); @@ -123,8 +177,9 @@ void DockerStylesComboModel::styleApplied(const KoChara= cterStyle *style) } m_usedStyles.insert(begin, m_sourceModel->indexForCharacterSty= le(*(style)).row()); // We use the ForCharacterStyle variant also for par= ag styles because the signal exist only in charStyle variant. TODO merge th= ese functions in StylesModel. they use the styleId anyway. } - //we do not reset the model here, as it will mess up the view's vi= sibility. perhaps this is very wrong. to be considered in case we have bugs. + beginResetModel(); createMapping(); + endResetModel(); } } = @@ -191,9 +246,16 @@ void DockerStylesComboModel::createMapping() } } } - m_proxyToSource << m_usedStyles << m_unusedStyles; + if (!m_usedStyles.isEmpty()) { + m_proxyToSource << UsedStyleId << 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 t= reated accordingly + } m_sourceToProxy.fill(-1, m_sourceModel->rowCount((QModelIndex()))); for (int i =3D 0; i < m_proxyToSource.count(); ++i) { - m_sourceToProxy[m_proxyToSource.at(i)] =3D i; + if (m_proxyToSource.at(i) >=3D 0) { //we do not need to map to the= titles + m_sourceToProxy[m_proxyToSource.at(i)] =3D i; + } } } diff --git a/plugins/textshape/dialogs/DockerStylesComboModel.h b/plugins/t= extshape/dialogs/DockerStylesComboModel.h index 933c83d..8c7d0dd 100644 --- a/plugins/textshape/dialogs/DockerStylesComboModel.h +++ b/plugins/textshape/dialogs/DockerStylesComboModel.h @@ -30,8 +30,20 @@ class DockerStylesComboModel : public StylesFilteredMode= lBase { Q_OBJECT public: + + enum CategoriesInternalIds { + UsedStyleId =3D -32000, + UnusedStyleId =3D -32001 + }; + explicit DockerStylesComboModel(QObject *parent =3D 0); = + virtual Qt::ItemFlags flags(const QModelIndex &index) const; + + virtual QModelIndex index(int row, int column, const QModelIndex &pare= nt) const; + + virtual QVariant data(const QModelIndex & index, int role =3D Qt::Disp= layRole) const; + void setStyleManager(KoStyleManager *sm); = void setInitialUsedStyles(QVector usedStyles); diff --git a/plugins/textshape/dialogs/SimpleCharacterWidget.cpp b/plugins/= textshape/dialogs/SimpleCharacterWidget.cpp index 744b8b9..0e3b01d 100644 --- a/plugins/textshape/dialogs/SimpleCharacterWidget.cpp +++ b/plugins/textshape/dialogs/SimpleCharacterWidget.cpp @@ -94,7 +94,7 @@ SimpleCharacterWidget::SimpleCharacterWidget(TextTool *to= ol, QWidget *parent) = m_stylesModel->setStyleThumbnailer(m_thumbnailer); widget.characterStyleCombo->setStylesModel(m_sortedStylesModel); - connect(widget.characterStyleCombo, SIGNAL(selected(int)), this, SLOT(= styleSelected(int))); + connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), th= is, SLOT(styleSelected(QModelIndex&))); connect(widget.characterStyleCombo, SIGNAL(newStyleRequested(QString))= , this, SIGNAL(newStyleRequested(QString))); connect(widget.characterStyleCombo, SIGNAL(newStyleRequested(QString))= , this, SIGNAL(doneWithFocus())); connect(widget.characterStyleCombo, SIGNAL(showStyleManager(int)), thi= s, SLOT(slotShowStyleManager(int))); @@ -119,10 +119,10 @@ void SimpleCharacterWidget::setStyleManager(KoStyleMa= nager *sm) } m_styleManager =3D sm; //we want to disconnect this before setting the stylemanager. Populati= ng the model apparently selects the first inserted item. We don't want this= to actually set a new style. - disconnect(widget.characterStyleCombo, SIGNAL(selected(int)), this, SL= OT(styleSelected(int))); + disconnect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)),= this, SLOT(styleSelected(QModelIndex&))); m_stylesModel->setStyleManager(sm); m_sortedStylesModel->setStyleManager(sm); - connect(widget.characterStyleCombo, SIGNAL(selected(int)), this, SLOT(= styleSelected(int))); + connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), th= is, SLOT(styleSelected(QModelIndex&))); connect(m_styleManager, SIGNAL(styleApplied(const KoCharacterStyle*)),= this, SLOT(slotCharacterStyleApplied(const KoCharacterStyle*))); } = @@ -165,11 +165,12 @@ void SimpleCharacterWidget::setCurrentFormat(const QT= extCharFormat& format, cons } } } - disconnect(widget.characterStyleCombo, SIGNAL(selected(int)), this= , SLOT(styleSelected(int))); - widget.characterStyleCombo->setCurrentIndex((useParagraphStyle)?0:= m_sortedStylesModel->indexForCharacterStyle(*style).row()); + disconnect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex= &)), this, SLOT(styleSelected(QModelIndex&))); + //TODO, this is very brittle index 1 is because index 0 is the ti= tle. The proper solution to that would be for the "None" style to have a st= yleId 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()); widget.characterStyleCombo->setStyleIsOriginal(unchanged); widget.characterStyleCombo->slotUpdatePreview(); - connect(widget.characterStyleCombo, SIGNAL(selected(int)), this, S= LOT(styleSelected(int))); + connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&))= , this, SLOT(styleSelected(QModelIndex&))); } } = @@ -220,14 +221,27 @@ void SimpleCharacterWidget::setCurrentBlockFormat(con= st QTextBlockFormat &format m_currentBlockFormat =3D format; = m_stylesModel->setCurrentParagraphStyle(format.intProperty(KoParagraph= Style::StyleId)); - disconnect(widget.characterStyleCombo, SIGNAL(selected(int)), this, SL= OT(styleSelected(int))); + disconnect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)),= this, SLOT(styleSelected(QModelIndex&))); widget.characterStyleCombo->slotUpdatePreview(); - connect(widget.characterStyleCombo, SIGNAL(selected(int)), this, SLOT(= styleSelected(int))); + connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), th= is, SLOT(styleSelected(QModelIndex&))); } = void SimpleCharacterWidget::styleSelected(int index) { - KoCharacterStyle *charStyle =3D m_styleManager->characterStyle(m_sorte= dStylesModel->index(index).internalId()); + KoCharacterStyle *charStyle =3D m_styleManager->characterStyle(m_sorte= dStylesModel->index(index, 0, QModelIndex()).internalId()); + + //if the selected item correspond to a null characterStyle, send the n= ull pointer. the tool should set the characterStyle as per paragraph + emit characterStyleSelected(charStyle); + emit doneWithFocus(); +} + +void SimpleCharacterWidget::styleSelected(QModelIndex &index) +{ + if (!index.isValid()) { + emit doneWithFocus(); + return; + } + KoCharacterStyle *charStyle =3D m_styleManager->characterStyle(index.i= nternalId()); = //if the selected item correspond to a null characterStyle, send the n= ull pointer. the tool should set the characterStyle as per paragraph emit characterStyleSelected(charStyle); @@ -236,7 +250,7 @@ void SimpleCharacterWidget::styleSelected(int index) = void SimpleCharacterWidget::slotShowStyleManager(int index) { - int styleId =3D m_sortedStylesModel->index(index).internalId(); + int styleId =3D m_sortedStylesModel->index(index, 0, QModelIndex()).in= ternalId(); emit showStyleManager(styleId); emit doneWithFocus(); } diff --git a/plugins/textshape/dialogs/SimpleCharacterWidget.h b/plugins/te= xtshape/dialogs/SimpleCharacterWidget.h index 71fc022..8d4850d 100644 --- a/plugins/textshape/dialogs/SimpleCharacterWidget.h +++ b/plugins/textshape/dialogs/SimpleCharacterWidget.h @@ -55,6 +55,7 @@ private slots: void fontFamilyActivated(int index); void fontSizeActivated(int index); void styleSelected(int index); + void styleSelected(QModelIndex &index); void slotShowStyleManager(int index); = signals: diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp b/plugins/= textshape/dialogs/SimpleParagraphWidget.cpp index 7337242..c01cea5 100644 --- a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp +++ b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp @@ -103,7 +103,7 @@ SimpleParagraphWidget::SimpleParagraphWidget(TextTool *= tool, QWidget *parent) = m_stylesModel->setStyleThumbnailer(m_thumbnailer); widget.paragraphStyleCombo->setStylesModel(m_sortedStylesModel); - connect(widget.paragraphStyleCombo, SIGNAL(selected(int)), this, SLOT(= styleSelected(int))); + connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&)), th= is, SLOT(styleSelected(QModelIndex&))); connect(widget.paragraphStyleCombo, SIGNAL(newStyleRequested(QString))= , this, SIGNAL(newStyleRequested(QString))); connect(widget.paragraphStyleCombo, SIGNAL(newStyleRequested(QString))= , this, SIGNAL(doneWithFocus())); connect(widget.paragraphStyleCombo, SIGNAL(showStyleManager(int)), thi= s, SLOT(slotShowStyleManager(int))); @@ -278,13 +278,13 @@ void SimpleParagraphWidget::setCurrentFormat(const QT= extBlockFormat &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 und= o stack, the change tracking,... - disconnect(widget.paragraphStyleCombo, SIGNAL(selected(int)), this= , SLOT(styleSelected(int))); + disconnect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex= &)), this, SLOT(styleSelected(QModelIndex&))); m_sortedStylesModel->styleApplied(style); widget.paragraphStyleCombo->setCurrentIndex(m_sortedStylesModel->i= ndexForParagraphStyle(*style).row()); widget.paragraphStyleCombo->setStyleIsOriginal(unchanged); m_stylesModel->setCurrentParagraphStyle(id); widget.paragraphStyleCombo->slotUpdatePreview(); - connect(widget.paragraphStyleCombo, SIGNAL(selected(int)), this, S= LOT(styleSelected(int))); + connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&))= , this, SLOT(styleSelected(QModelIndex&))); } } = @@ -299,10 +299,10 @@ void SimpleParagraphWidget::setStyleManager(KoStyleMa= nager *sm) } m_styleManager =3D sm; //we want to disconnect this before setting the stylemanager. Populati= ng the model apparently selects the first inserted item. We don't want this= to actually set a new style. - disconnect(widget.paragraphStyleCombo, SIGNAL(selected(int)), this, SL= OT(styleSelected(int))); + disconnect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&)),= this, SLOT(styleSelected(QModelIndex&))); m_stylesModel->setStyleManager(sm); m_sortedStylesModel->setStyleManager(sm); - connect(widget.paragraphStyleCombo, SIGNAL(selected(int)), this, SLOT(= styleSelected(int))); + connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&)), th= is, SLOT(styleSelected(QModelIndex&))); connect(m_styleManager, SIGNAL(styleApplied(const KoParagraphStyle*)),= this, SLOT(slotParagraphStyleApplied(const KoParagraphStyle*))); } = @@ -323,7 +323,19 @@ void SimpleParagraphWidget::listStyleChanged(int id) = void SimpleParagraphWidget::styleSelected(int index) { - KoParagraphStyle *paragStyle =3D m_styleManager->paragraphStyle(m_sort= edStylesModel->index(index).internalId()); + KoParagraphStyle *paragStyle =3D m_styleManager->paragraphStyle(m_sort= edStylesModel->index(index, 0, QModelIndex()).internalId()); + if (paragStyle) { + emit paragraphStyleSelected(paragStyle); + } + emit doneWithFocus(); +} + +void SimpleParagraphWidget::styleSelected(QModelIndex &index) +{ + if (!index.isValid()) { + return; + } + KoParagraphStyle *paragStyle =3D m_styleManager->paragraphStyle(index.= internalId()); if (paragStyle) { emit paragraphStyleSelected(paragStyle); } @@ -332,15 +344,13 @@ void SimpleParagraphWidget::styleSelected(int index) = void SimpleParagraphWidget::slotShowStyleManager(int index) { - int styleId =3D m_sortedStylesModel->index(index).internalId(); + int styleId =3D m_sortedStylesModel->index(index, 0, QModelIndex()).in= ternalId(); emit showStyleManager(styleId); emit doneWithFocus(); } = void SimpleParagraphWidget::slotParagraphStyleApplied(const KoParagraphSty= le *style) { - if (style) { - } m_sortedStylesModel->styleApplied(style); } = diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.h b/plugins/te= xtshape/dialogs/SimpleParagraphWidget.h index 6e0bed5..27c2061 100644 --- a/plugins/textshape/dialogs/SimpleParagraphWidget.h +++ b/plugins/textshape/dialogs/SimpleParagraphWidget.h @@ -63,6 +63,7 @@ signals: private slots: void listStyleChanged(int id); void styleSelected(int index); + void styleSelected(QModelIndex &index); void changeListLevel(int level); = private: diff --git a/plugins/textshape/dialogs/StylesCombo.cpp b/plugins/textshape/= dialogs/StylesCombo.cpp index 470903a..16f50a5 100644 --- a/plugins/textshape/dialogs/StylesCombo.cpp +++ b/plugins/textshape/dialogs/StylesCombo.cpp @@ -135,7 +135,7 @@ void StylesCombo::slotSelectionChanged(int index) m_selectedItem =3D index; m_preview->setPreview(m_stylesModel->stylePreview(index, m_preview->av= ailableSize())); update(); - emit selectionChanged(index); +// emit selectionChanged(index); } = void StylesCombo::slotItemClicked(QModelIndex index) @@ -143,8 +143,11 @@ void StylesCombo::slotItemClicked(QModelIndex index) //this slot allows us to emit a selected signal. There is a bit of red= undancy if the item clicked was indeed a new selection, where we also emit = the selectionChanged signal from the slot above. m_selectedItem =3D index.row(); m_preview->setPreview(m_stylesModel->stylePreview(m_selectedItem, m_pr= eview->availableSize())); + m_currentIndex =3D index; update(); emit selected(m_selectedItem); + emit selected(index); + hidePopup(); //the editor event has accepted the mouseReleased event. = Call hidePopup ourselves then. } = void StylesCombo::slotUpdatePreview() @@ -194,6 +197,11 @@ void StylesCombo::slotDeleteStyle(QModelIndex index) emit deleteStyle(index.row()); } = +void StylesCombo::slotModelReset() +{ + m_view->reset(); +} + void StylesCombo::showEditIcon(bool show){ StylesDelegate *delegate =3D new StylesDelegate(); delegate->setEditButtonEnable(show); diff --git a/plugins/textshape/dialogs/StylesCombo.h b/plugins/textshape/di= alogs/StylesCombo.h index 4916ff1..d6ce959 100644 --- a/plugins/textshape/dialogs/StylesCombo.h +++ b/plugins/textshape/dialogs/StylesCombo.h @@ -66,6 +66,7 @@ signals: * to be noted that this signal is also emitted when an item is selec= ted again. * @param index: the index of the selected item. */ void selected(int index); + void selected(QModelIndex &index); = /** This is emitted when a selection is changed (programatically or by= user interaction). It is * to be noted that this signal is _not_ emitted when an item is sele= cted again. Not even if it @@ -92,6 +93,7 @@ private slots: void slotSelectionChanged(int index); void slotItemClicked(QModelIndex); void slotPreviewClicked(); + void slotModelReset(); = private: AbstractStylesModel *m_stylesModel; @@ -99,6 +101,7 @@ private: QListView *m_view; int m_selectedItem; bool m_originalStyle; + QModelIndex m_currentIndex; }; = #endif //STYLESCOMBO_H diff --git a/plugins/textshape/dialogs/StylesDelegate.cpp b/plugins/textsha= pe/dialogs/StylesDelegate.cpp index 9ad9de5..76d3b97 100644 --- a/plugins/textshape/dialogs/StylesDelegate.cpp +++ b/plugins/textshape/dialogs/StylesDelegate.cpp @@ -20,9 +20,12 @@ = #include "StylesDelegate.h" = +#include "AbstractStylesModel.h" + #include = #include +#include #include #include #include @@ -52,29 +55,30 @@ void StylesDelegate::paint(QPainter *painter, const QSt= yleOptionViewItem &option { QStyleOptionViewItemV4 option =3D optionV1; initStyleOption(&option, index); - QStyledItemDelegate::paint(painter, option, index); + if (!index.data(AbstractStylesModel::isTitleRole).toBool()) { + QStyledItemDelegate::paint(painter, option, index); = - //the following is needed to find out if the view has vertical scrollb= ars. If there is no view just paint and do not attempt to draw the control = buttons. - //this is needed because it seems that the option.rect given does not = exclude the vertical scrollBar. This means that we can draw the button in a= n area that is going to be covered by the vertical scrollBar. - const QAbstractItemView *view =3D static_cast(option.widget); - if (!view){ - return; - } - QScrollBar *scrollBar =3D view->verticalScrollBar(); - int scrollBarWidth =3D 0; - if (scrollBar->isVisible()) { - scrollBarWidth =3D scrollBar->width(); - } + //the following is needed to find out if the view has vertical scr= ollbars. If there is no view just paint and do not attempt to draw the cont= rol buttons. + //this is needed because it seems that the option.rect given does = not exclude the vertical scrollBar. This means that we can draw the button = in an area that is going to be covered by the vertical scrollBar. + const QAbstractItemView *view =3D static_cast(option.widget); + if (!view){ + return; + } + QScrollBar *scrollBar =3D view->verticalScrollBar(); + int scrollBarWidth =3D 0; + if (scrollBar->isVisible()) { + scrollBarWidth =3D scrollBar->width(); + } = - if (!index.isValid() || !(option.state & QStyle::State_MouseOver)) { - return; - } - // Delete style button. - int dx1 =3D option.rect.width() - qMin(option.rect.height()-2, m_butto= nSize) - m_buttonSize - m_buttonDistance -2; - int dy1 =3D 1 + (option.rect.height()-qMin(option.rect.height(), m_but= tonSize))/2; - int dx2 =3D -m_buttonSize - m_buttonDistance -2; - int dy2 =3D -1 -(option.rect.height()-qMin(option.rect.height(), m_but= tonSize))/2; -/* TODO: when we can safely delete styles, re-enable this + if (!index.isValid() || !(option.state & QStyle::State_MouseOver))= { + return; + } + // Delete style button. + int dx1 =3D option.rect.width() - qMin(option.rect.height()-2, m_b= uttonSize) - m_buttonSize - m_buttonDistance -2; + int dy1 =3D 1 + (option.rect.height()-qMin(option.rect.height(), m= _buttonSize))/2; + int dx2 =3D -m_buttonSize - m_buttonDistance -2; + int dy2 =3D -1 -(option.rect.height()-qMin(option.rect.height(), m= _buttonSize))/2; + /* TODO: when we can safely delete styles, re-enable this QStyleOptionButton optDel; if (!m_deleteButtonPressed) { optDel.state |=3D QStyle::State_Enabled; @@ -84,22 +88,104 @@ void StylesDelegate::paint(QPainter *painter, const QS= tyleOptionViewItem &option optDel.rect =3D option.rect.adjusted(dx1 - scrollBarWidth, dy1, dx2 - = scrollBarWidth, dy2); view->style()->drawControl(QStyle::CE_PushButton, &optDel, painter, 0); */ - // Open style manager dialog button. - if (!m_enableEditButton) { // when we don't want edit icon - return; + // Open style manager dialog button. + if (!m_enableEditButton) { // when we don't want edit icon + return; + } + dx1 =3D option.rect.width() - qMin(option.rect.height()-2, m_butto= nSize) -2; + dy1 =3D 1 + (option.rect.height()-qMin(option.rect.height(), m_but= tonSize))/2; + dx2 =3D -2; + dy2 =3D -1 -(option.rect.height()-qMin(option.rect.height(), m_but= tonSize))/2; + QStyleOptionButton optEdit; + if (!m_editButtonPressed) { + optEdit.state |=3D QStyle::State_Enabled; + } + optEdit.icon =3D koIcon("document-properties"); + optEdit.features |=3D QStyleOptionButton::Flat; + optEdit.rect =3D option.rect.adjusted(dx1 - scrollBarWidth, dy1, d= x2 - scrollBarWidth, dy2); + view->style()->drawControl(QStyle::CE_PushButton, &optEdit, painte= r, 0); } - dx1 =3D option.rect.width() - qMin(option.rect.height()-2, m_buttonSiz= e) -2; - dy1 =3D 1 + (option.rect.height()-qMin(option.rect.height(), m_buttonS= ize))/2; - dx2 =3D -2; - dy2 =3D -1 -(option.rect.height()-qMin(option.rect.height(), m_buttonS= ize))/2; - QStyleOptionButton optEdit; - if (!m_editButtonPressed) { - optEdit.state |=3D QStyle::State_Enabled; + else { + const QString category =3D index.data().toString(); + const QRect optRect =3D option.rect; + QFont font(QApplication::font()); + font.setBold(true); + const QFontMetrics fontMetrics =3D QFontMetrics(font); + QColor outlineColor =3D option.palette.text().color(); + outlineColor.setAlphaF(0.35); + //BEGIN: top left corner + { + painter->save(); + painter->setPen(outlineColor); + const QPointF topLeft(optRect.topLeft()); + QRectF arc(topLeft, QSizeF(4, 4)); + arc.translate(0.5, 0.5); + painter->drawArc(arc, 1440, 1440); + painter->restore(); + } + //END: top left corner + //BEGIN: left vertical line + { + QPoint start(optRect.topLeft()); + start.ry() +=3D 3; + QPoint verticalGradBottom(optRect.topLeft()); + verticalGradBottom.ry() +=3D fontMetrics.height() + 5; + QLinearGradient gradient(start, verticalGradBottom); + gradient.setColorAt(0, outlineColor); + gradient.setColorAt(1, Qt::transparent); + painter->fillRect(QRect(start, QSize(1, fontMetrics.height() += 5)), gradient); + } + //END: left vertical line + //BEGIN: horizontal line + { + QPoint start(optRect.topLeft()); + start.rx() +=3D 3; + QPoint horizontalGradTop(optRect.topLeft()); + horizontalGradTop.rx() +=3D optRect.width() - 6; + painter->fillRect(QRect(start, QSize(optRect.width() - 6, 1)),= outlineColor); + } + //END: horizontal line + //BEGIN: top right corner + { + painter->save(); + painter->setPen(outlineColor); + QPointF topRight(optRect.topRight()); + topRight.rx() -=3D 4; + QRectF arc(topRight, QSizeF(4, 4)); + arc.translate(0.5, 0.5); + painter->drawArc(arc, 0, 1440); + painter->restore(); + } + //END: top right corner + //BEGIN: right vertical line + { + QPoint start(optRect.topRight()); + start.ry() +=3D 3; + QPoint verticalGradBottom(optRect.topRight()); + verticalGradBottom.ry() +=3D fontMetrics.height() + 5; + QLinearGradient gradient(start, verticalGradBottom); + gradient.setColorAt(0, outlineColor); + gradient.setColorAt(1, Qt::transparent); + painter->fillRect(QRect(start, QSize(1, fontMetrics.height() += 5)), gradient); + } + //END: right vertical line + //BEGIN: text + { + QRect textRect(option.rect); + textRect.setTop(textRect.top() + 7); + textRect.setLeft(textRect.left() + 7); + textRect.setHeight(fontMetrics.height()); + textRect.setRight(textRect.right() - 7); + painter->save(); + painter->setFont(font); + QColor penColor(option.palette.text().color()); + penColor.setAlphaF(0.6); + painter->setPen(penColor); + painter->drawText(textRect, Qt::AlignLeft | Qt::AlignVCenter, = category); + painter->restore(); + } + //END: text } - optEdit.icon =3D koIcon("document-properties"); - optEdit.features |=3D QStyleOptionButton::Flat; - optEdit.rect =3D option.rect.adjusted(dx1 - scrollBarWidth, dy1, dx2 -= scrollBarWidth, dy2); - view->style()->drawControl(QStyle::CE_PushButton, &optEdit, painter, 0= ); } = QSize StylesDelegate::sizeHint(const QStyleOptionViewItem &option, const Q= ModelIndex &index) const @@ -159,6 +245,11 @@ bool StylesDelegate::editorEvent(QEvent *event, QAbstr= actItemModel *model, const m_deleteButtonPressed =3D false; m_editButtonPressed =3D false; emit needsUpdate(index); + + if (index.flags() =3D=3D Qt::NoItemFlags) { //if the item is NoIte= mFlagged, it means it is a separator in the view. In that case, we should n= ot close the combo's drop down. + return true; + } + QMouseEvent *mouseEvent =3D static_cast(event); int dx1 =3D option.rect.width() - qMin(option.rect.height()-2, m_b= uttonSize) - m_buttonSize - m_buttonDistance -2; int dy1 =3D 1 + (option.rect.height()-qMin(option.rect.height(), m= _buttonSize))/2; @@ -181,7 +272,7 @@ bool StylesDelegate::editorEvent(QEvent *event, QAbstra= ctItemModel *model, const return true; } emit clickedInItem(index); - return false; + return true; //returning true here means the QComboBox mouseReleas= e code will not get called. The effect of it is that hidePopup will not get= called. StylesCombo calls it in the corresponding slot. } if (event->type() =3D=3D QEvent::MouseMove) { QMouseEvent *mouseEvent =3D static_cast(event); diff --git a/plugins/textshape/dialogs/StylesFilteredModelBase.cpp b/plugin= s/textshape/dialogs/StylesFilteredModelBase.cpp index f448a3c..f84df16 100644 --- a/plugins/textshape/dialogs/StylesFilteredModelBase.cpp +++ b/plugins/textshape/dialogs/StylesFilteredModelBase.cpp @@ -46,11 +46,13 @@ QModelIndex StylesFilteredModelBase::index(int row, int= column, const QModelInde = QModelIndex StylesFilteredModelBase::parent(const QModelIndex &child) const { + Q_UNUSED(child); return QModelIndex(); } = int StylesFilteredModelBase::columnCount(const QModelIndex &parent) const { + Q_UNUSED(parent); return 1; } = @@ -124,7 +126,16 @@ QImage StylesFilteredModelBase::stylePreview(int row, = QSize size) return m_sourceModel->stylePreview(m_proxyToSource.at(row), size); = } +/* +QImage StylesFilteredModelBase::stylePreview(QModelIndex &index, QSize siz= e) +{ + if (!index.isValid()) { + return QImage(); + } + return m_sourceModel->stylePreview(index, size); //TODO be carefull th= ere. this is assuming the sourceModel is only using the internalId, and the= index's internalId matches the model's = +} +*/ void StylesFilteredModelBase::setStylesModel(AbstractStylesModel *sourceMo= del) { if (m_sourceModel =3D=3D sourceModel) { diff --git a/plugins/textshape/dialogs/StylesFilteredModelBase.h b/plugins/= textshape/dialogs/StylesFilteredModelBase.h index 4a81c0a..b39a5fa 100644 --- a/plugins/textshape/dialogs/StylesFilteredModelBase.h +++ b/plugins/textshape/dialogs/StylesFilteredModelBase.h @@ -71,6 +71,7 @@ public: * If size isn't specified, the default size of the given @class KoSt= yleThumbnailer is used. */ virtual QImage stylePreview(int row, QSize size =3D QSize()); +// virtual QImage stylePreview(QModelIndex &index, QSize size =3D QSize= ()); = virtual AbstractStylesModel::Type stylesType() const; = diff --git a/plugins/textshape/dialogs/StylesModel.cpp b/plugins/textshape/= dialogs/StylesModel.cpp index 5c42ff4..2ac95fa 100644 --- a/plugins/textshape/dialogs/StylesModel.cpp +++ b/plugins/textshape/dialogs/StylesModel.cpp @@ -78,6 +78,7 @@ QModelIndex StylesModel::index(int row, int column, const= QModelIndex &parent) c = QModelIndex StylesModel::parent(const QModelIndex &child) const { + Q_UNUSED(child); return QModelIndex(); } = @@ -90,6 +91,7 @@ int StylesModel::rowCount(const QModelIndex &parent) const = int StylesModel::columnCount(const QModelIndex &parent) const { + Q_UNUSED(parent); return 1; } = @@ -236,7 +238,48 @@ QImage StylesModel::stylePreview(int row, QSize size) } return QImage(); } - +/* +QImage StylesModel::stylePreview(QModelIndex &index, QSize size) +{ + if (!m_styleManager || !m_styleThumbnailer) { + return QImage(); + } + if (m_modelType =3D=3D StylesModel::ParagraphStyle) { + KoParagraphStyle *usedStyle =3D 0; + usedStyle =3D m_styleManager->paragraphStyle(index.internalId()); + if (usedStyle) { + return m_styleThumbnailer->thumbnail(usedStyle, size); + } + if (!usedStyle && m_draftParStyleList.contains(index.internalId())= ) { + return m_styleThumbnailer->thumbnail(m_draftParStyleList[index= .internalId()], size); + } + } + else { + KoCharacterStyle *usedStyle =3D 0; + if (index.internalId() =3D=3D -1) { + usedStyle =3D static_cast(m_currentParagrap= hStyle); + if (!usedStyle) { + usedStyle =3D m_defaultCharacterStyle; + } + usedStyle->setName(i18n("None")); + if (usedStyle->styleId() >=3D 0) { + usedStyle->setStyleId(-usedStyle->styleId()); //this style= is not managed by the styleManager but its styleId will be used in the thu= mbnail cache as part of the key. + } + return m_styleThumbnailer->thumbnail(usedStyle, m_currentParag= raphStyle, size); + } + else { + usedStyle =3D m_styleManager->characterStyle(index.internalId(= )); + if (usedStyle) { + return m_styleThumbnailer->thumbnail(usedStyle, m_currentP= aragraphStyle, size); + } + if (!usedStyle && m_draftCharStyleList.contains(index.internal= Id())) { + return m_styleThumbnailer->thumbnail(m_draftCharStyleList[= index.internalId()],m_currentParagraphStyle, size); + } + } + } + return QImage(); +} +*/ void StylesModel::setStyleManager(KoStyleManager *sm) { if (sm =3D=3D m_styleManager) diff --git a/plugins/textshape/dialogs/StylesModel.h b/plugins/textshape/di= alogs/StylesModel.h index c904d39..cd8117a 100644 --- a/plugins/textshape/dialogs/StylesModel.h +++ b/plugins/textshape/dialogs/StylesModel.h @@ -107,6 +107,7 @@ public: * If size isn't specified, the default size of the given @class KoSt= yleThumbnailer is used. */ QImage stylePreview(int row, QSize size =3D QSize()); +// QImage stylePreview(QModelIndex &index, QSize size =3D QSize()); = /** Specifies which paragraph style is currently the active one (on th= e current paragraph). This is used in order to properly preview the "As par= agraph" virtual character style. */ void setCurrentParagraphStyle(int styleId);