[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [calligra/textshape-stylesWidget-PierreSt] plugins/textshape/dialogs: tempo
From: Pierre Stirnweiss <pstirnweiss () googlemail ! com>
Date: 2012-12-23 13:16:33
Message-ID: 20121223131633.35082A6091 () git ! kde ! org
[Download RAW message or body]
Git commit ab191fb238011a53af4867231422de3e61c3f89e by Pierre Stirnweiss.
Committed on 16/12/2012 at 14:46.
Pushed by pstirnweiss into branch 'textshape-stylesWidget-PierreSt'.
tempo
M +1 -0 plugins/textshape/dialogs/AbstractStylesModel.h
M +65 -8 plugins/textshape/dialogs/DockerStylesComboModel.cpp
M +4 -4 plugins/textshape/dialogs/DockerStylesComboModel.h
M +38 -8 plugins/textshape/dialogs/SimpleCharacterWidget.cpp
M +1 -0 plugins/textshape/dialogs/SimpleCharacterWidget.h
M +21 -4 plugins/textshape/dialogs/SimpleParagraphWidget.cpp
M +1 -0 plugins/textshape/dialogs/SimpleParagraphWidget.h
M +31 -9 plugins/textshape/dialogs/StylesCombo.cpp
M +4 -2 plugins/textshape/dialogs/StylesCombo.h
M +11 -0 plugins/textshape/dialogs/StylesFilteredModelBase.cpp
M +1 -0 plugins/textshape/dialogs/StylesFilteredModelBase.h
M +42 -0 plugins/textshape/dialogs/StylesModel.cpp
M +1 -0 plugins/textshape/dialogs/StylesModel.h
http://commits.kde.org/calligra/ab191fb238011a53af4867231422de3e61c3f89e
diff --git a/plugins/textshape/dialogs/AbstractStylesModel.h \
b/plugins/textshape/dialogs/AbstractStylesModel.h index 6fddd0e..87b5a57 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 \
KoStyleThumbnailer is used.
*/
virtual QImage stylePreview(int row, QSize size = QSize()) = 0;
+ virtual QImage stylePreview(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/DockerStylesComboModel.cpp \
b/plugins/textshape/dialogs/DockerStylesComboModel.cpp index 306dde6..0a62cba 100644
--- a/plugins/textshape/dialogs/DockerStylesComboModel.cpp
+++ b/plugins/textshape/dialogs/DockerStylesComboModel.cpp
@@ -40,7 +40,7 @@ Qt::ItemFlags DockerStylesComboModel::flags(const QModelIndex \
&index) const }
return (Qt::ItemIsEnabled | Qt::ItemIsSelectable);
}
-
+/*
QModelIndex DockerStylesComboModel::parent(const QModelIndex &child) const
{
if (child.data(isTitleRole).toBool()) {
@@ -59,24 +59,41 @@ QModelIndex DockerStylesComboModel::parent(const QModelIndex \
&child) const
int DockerStylesComboModel::rowCount(const QModelIndex &parent) const
{
+ kDebug() << "parent: " << parent;
+ kDebug() << "parent isValid: " << parent.isValid();
if (!parent.isValid()) {
- return 2;
+ return m_proxyToSource.count();
+// return 2;
}
if (parent.internalId() == UsedStyleId) {
+ kDebug() << "rowCount used: "<< m_usedStyles.count();
return m_usedStyles.count();
}
if (parent.internalId() == UnusedStyleId) {
+ kDebug() << "rowCount unused: " << m_sourceModel->rowCount() - \
m_usedStyles.count(); return (m_sourceModel->rowCount() - m_usedStyles.count());
}
return 0;
}
-
+*/
QModelIndex DockerStylesComboModel::index(int row, int column, const QModelIndex \
&parent) const {
if (row < 0 || column != 0)
return QModelIndex();
if (!parent.isValid()) {
+ if (row >= m_proxyToSource.count()) {
+ return QModelIndex();
+ }
+ return createIndex(row, column, (m_proxyToSource.at(row) >= \
0)?int(m_sourceModel->index(m_proxyToSource.at(row), 0, \
QModelIndex()).internalId()):m_proxyToSource.at(row)); + }
+ return QModelIndex();
+ /*
+ kDebug() << "index row: " << row;
+ if (row < 0 || column != 0)
+ return QModelIndex();
+
+ if (!parent.isValid()) {
if (row >= 2) {
return QModelIndex();
}
@@ -98,14 +115,51 @@ QModelIndex DockerStylesComboModel::index(int row, int column, \
const QModelIndex if (row >= m_proxyToSource.count()) {
return QModelIndex();
}
- return createIndex(row, 0, int(m_sourceModel->index(m_proxyToSource.at(row), \
0, QModelIndex()).internalId())); + kDebug() << "proxyToSource count: " << \
m_proxyToSource.count(); + kDebug() << "parent: " << parent;
+ kDebug() << "parent internalId: " << parent.internalId();
+ kDebug() << "parent rowCount: " << rowCount(parent);
+ kDebug() << "parent internal id == UsedStyle: " << \
(parent.internalId()==UsedStyleId); + kDebug() << "m_usedStyle count: " << \
m_usedStyles.count(); + kDebug() << "row+count: " << m_usedStyles.count()+row;
+ return createIndex(row, 0, \
int(m_sourceModel->index(m_proxyToSource.at((parent.internalId()==UsedStyleId)?row:m_usedStyles.count()+row), \
0, QModelIndex()).internalId())); }
return QModelIndex();
+ */
}
QVariant DockerStylesComboModel::data(const QModelIndex &index, int role) const
{
- if (!index.isValid()) {
+ if (!index.isValid())
+ return QVariant();
+
+ switch (role){
+ case AbstractStylesModel::isTitleRole: {
+ if (index.internalId() == UsedStyleId || index.internalId() == \
UnusedStyleId) { + return true;
+ }
+ }
+ case Qt::DisplayRole: {
+ if (index.internalId() == UsedStyleId) {
+ return i18n("Used Styles");
+ }
+ if (index.internalId() == 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();
+
+/* if (!index.isValid()) {
return QVariant();
}
@@ -129,7 +183,7 @@ QVariant DockerStylesComboModel::data(const QModelIndex &index, \
int role) const return QVariant();
}
if (index.parent().isValid()) {
- return m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at(index.row()), \
0, QModelIndex()), role); + return \
m_sourceModel->data(m_sourceModel->index(m_proxyToSource.at((index.parent().internalId()==UsedStyleId)?index.row():m_usedStyles.count()+index.row()), \
0, QModelIndex()), role); }
// if (index.parent().isValid() && index.parent().internalId() == \
OriginalStyleId) { // return \
m_sourceModel->data(m_sourceModel->index(index.row() + m_modifiedStylesCount, 0, \
QModelIndex()), role); @@ -150,6 +204,7 @@ QVariant \
DockerStylesComboModel::data(const QModelIndex &index, int role) const }
return QVariant();
+*/
}
void DockerStylesComboModel::setInitialUsedStyles(QVector<int> usedStyles)
@@ -309,9 +364,11 @@ void DockerStylesComboModel::createMapping()
}
}
}
- m_proxyToSource << m_usedStyles << m_unusedStyles;
+ m_proxyToSource << UsedStyleId << m_usedStyles << UnusedStyleId << \
m_unusedStyles; //UsedStyleId and -UnusedStyleId will be detected as title (in index \
method) and will be treated accordingly m_sourceToProxy.fill(-1, \
m_sourceModel->rowCount((QModelIndex()))); for (int i = 0; i < \
m_proxyToSource.count(); ++i) {
- m_sourceToProxy[m_proxyToSource.at(i)] = i;
+ if (m_proxyToSource.at(i) >= 0) { //we do not need to map to the titles
+ m_sourceToProxy[m_proxyToSource.at(i)] = i;
+ }
}
}
diff --git a/plugins/textshape/dialogs/DockerStylesComboModel.h \
b/plugins/textshape/dialogs/DockerStylesComboModel.h index 46f70ab..169d177 100644
--- a/plugins/textshape/dialogs/DockerStylesComboModel.h
+++ b/plugins/textshape/dialogs/DockerStylesComboModel.h
@@ -32,19 +32,19 @@ class DockerStylesComboModel : public StylesFilteredModelBase
public:
enum CategoriesInternalIds {
- UsedStyleId = -1,
- UnusedStyleId = -2
+ UsedStyleId = -32000,
+ UnusedStyleId = -32001
};
explicit DockerStylesComboModel(QObject *parent = 0);
virtual Qt::ItemFlags flags(const QModelIndex &index) const;
- virtual QModelIndex parent(const QModelIndex &child) const;
+// virtual QModelIndex parent(const QModelIndex &child) const;
virtual QModelIndex index(int row, int column, const QModelIndex &parent) const;
- virtual int rowCount(const QModelIndex &parent) const;
+// virtual int rowCount(const QModelIndex &parent) const;
virtual QVariant data(const QModelIndex & index, int role = Qt::DisplayRole) \
const;
diff --git a/plugins/textshape/dialogs/SimpleCharacterWidget.cpp \
b/plugins/textshape/dialogs/SimpleCharacterWidget.cpp index 904d237..3df64d7 100644
--- a/plugins/textshape/dialogs/SimpleCharacterWidget.cpp
+++ b/plugins/textshape/dialogs/SimpleCharacterWidget.cpp
@@ -94,7 +94,8 @@ SimpleCharacterWidget::SimpleCharacterWidget(TextTool *tool, \
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(int)), this, SLOT(styleSelected(int))); + \
connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
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)), this, \
SLOT(slotShowStyleManager(int))); @@ -119,10 +120,12 @@ void \
SimpleCharacterWidget::setStyleManager(KoStyleManager *sm) }
m_styleManager = sm;
//we want to disconnect this before setting the stylemanager. Populating 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, \
SLOT(styleSelected(int))); +// disconnect(widget.characterStyleCombo, \
SIGNAL(selected(int)), this, SLOT(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(int)), this, SLOT(styleSelected(int))); + \
connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&)));
connect(m_styleManager, SIGNAL(styleApplied(const KoCharacterStyle*)), this, \
SLOT(slotCharacterStyleApplied(const KoCharacterStyle*))); }
@@ -137,6 +140,7 @@ void SimpleCharacterWidget::setCurrentFormat(const \
QTextCharFormat& format, cons return;
}
m_currentCharFormat = format;
+ kDebug() << "set charFormat styleId: " << \
m_currentCharFormat.intProperty(KoCharacterStyle::StyleId);
KoCharacterStyle \
*style(m_styleManager->characterStyle(m_currentCharFormat.intProperty(KoCharacterStyle::StyleId)));
bool useParagraphStyle = false;
@@ -145,6 +149,7 @@ void SimpleCharacterWidget::setCurrentFormat(const \
QTextCharFormat& format, cons useParagraphStyle = true;
}
if (style) {
+ kDebug() << "style name: " << style->name();
bool unchanged = true;
QTextCharFormat comparisonFormat = refBlockCharFormat;
style->applyStyle(comparisonFormat);
@@ -165,11 +170,14 @@ void SimpleCharacterWidget::setCurrentFormat(const \
QTextCharFormat& 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(int)), this, \
SLOT(styleSelected(int))); + 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());
widget.characterStyleCombo->setStyleIsOriginal(unchanged);
widget.characterStyleCombo->slotUpdatePreview();
- connect(widget.characterStyleCombo, SIGNAL(selected(int)), this, \
SLOT(styleSelected(int))); +// connect(widget.characterStyleCombo, \
SIGNAL(selected(int)), this, SLOT(styleSelected(int))); + \
connect(widget.characterStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&))); }
}
@@ -220,14 +228,36 @@ void SimpleCharacterWidget::setCurrentBlockFormat(const \
QTextBlockFormat &format m_currentBlockFormat = format;
m_stylesModel->setCurrentParagraphStyle(format.intProperty(KoParagraphStyle::StyleId));
- disconnect(widget.characterStyleCombo, SIGNAL(selected(int)), this, \
SLOT(styleSelected(int))); +// disconnect(widget.characterStyleCombo, \
SIGNAL(selected(int)), this, SLOT(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&)), this, SLOT(styleSelected(QModelIndex&))); +// \
connect(widget.characterStyleCombo, SIGNAL(selected(int)), this, \
SLOT(styleSelected(int))); }
void SimpleCharacterWidget::styleSelected(int index)
{
KoCharacterStyle *charStyle = \
m_styleManager->characterStyle(m_sortedStylesModel->index(index, 0, \
QModelIndex()).internalId()); + kDebug() << "style selected num: " << index;
+
+ //if the selected item correspond to a null characterStyle, send the null \
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;
+ }
+ kDebug() << "index internalId: " << index.internalId();
+ KoCharacterStyle *charStyle = \
m_styleManager->characterStyle(index.internalId()); +
+ kDebug() << "charStyle: " << charStyle;
+ if (charStyle) {
+ kDebug() << "style name: " << charStyle->name();
+ }
//if the selected item correspond to a null characterStyle, send the null \
pointer. the tool should set the characterStyle as per paragraph emit \
characterStyleSelected(charStyle);
diff --git a/plugins/textshape/dialogs/SimpleCharacterWidget.h \
b/plugins/textshape/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 ea0f453..5f1e3c2 100644
--- a/plugins/textshape/dialogs/SimpleParagraphWidget.cpp
+++ b/plugins/textshape/dialogs/SimpleParagraphWidget.cpp
@@ -278,13 +278,15 @@ 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(int)), this, \
SLOT(styleSelected(int))); +// 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->indexForParagraphStyle(*style).row());
widget.paragraphStyleCombo->setStyleIsOriginal(unchanged);
m_stylesModel->setCurrentParagraphStyle(id);
widget.paragraphStyleCombo->slotUpdatePreview();
- connect(widget.paragraphStyleCombo, SIGNAL(selected(int)), this, \
SLOT(styleSelected(int))); +// connect(widget.paragraphStyleCombo, \
SIGNAL(selected(int)), this, SLOT(styleSelected(int))); + \
connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&))); }
}
@@ -299,10 +301,12 @@ void SimpleParagraphWidget::setStyleManager(KoStyleManager *sm)
}
m_styleManager = sm;
//we want to disconnect this before setting the stylemanager. Populating 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, \
SLOT(styleSelected(int))); +// disconnect(widget.paragraphStyleCombo, \
SIGNAL(selected(int)), this, SLOT(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(int)), this, SLOT(styleSelected(int))); + \
connect(widget.paragraphStyleCombo, SIGNAL(selected(QModelIndex&)), this, \
SLOT(styleSelected(QModelIndex&)));
connect(m_styleManager, SIGNAL(styleApplied(const KoParagraphStyle*)), this, \
SLOT(slotParagraphStyleApplied(const KoParagraphStyle*))); }
@@ -330,6 +334,19 @@ void SimpleParagraphWidget::styleSelected(int index)
emit doneWithFocus();
}
+void SimpleParagraphWidget::styleSelected(QModelIndex &index)
+{
+ kDebug() << "styleSelected. index: " << index;
+ if (!index.isValid()) {
+ return;
+ }
+ KoParagraphStyle *paragStyle = \
m_styleManager->paragraphStyle(index.internalId()); + if (paragStyle) {
+ emit paragraphStyleSelected(paragStyle);
+ }
+ emit doneWithFocus();
+}
+
void SimpleParagraphWidget::slotShowStyleManager(int index)
{
int styleId = m_sortedStylesModel->index(index, 0, QModelIndex()).internalId();
diff --git a/plugins/textshape/dialogs/SimpleParagraphWidget.h \
b/plugins/textshape/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 347c7a8..f2d5ffb 100644
--- a/plugins/textshape/dialogs/StylesCombo.cpp
+++ b/plugins/textshape/dialogs/StylesCombo.cpp
@@ -33,8 +33,8 @@
StylesCombo::StylesCombo(QWidget *parent)
: QComboBox(parent),
m_stylesModel(0),
-// m_view(new QListView()),
- m_view(new QTreeView()),
+ m_view(new QListView()),
+// m_view(new QTreeView()),
m_selectedItem(-1),
m_originalStyle(true)
{
@@ -54,10 +54,10 @@ StylesCombo::StylesCombo(QWidget *parent)
m_view->setMinimumWidth(250);
m_view->setMouseTracking(true);
- m_view->setRootIsDecorated(false);
- m_view->setItemsExpandable(false);
- m_view->setHeaderHidden(true);
- m_view->setIndentation(0);
+// m_view->setRootIsDecorated(false);
+// m_view->setItemsExpandable(false);
+// m_view->setHeaderHidden(true);
+// m_view->setIndentation(0);
setView(m_view);
view()->viewport()->installEventFilter(this);
@@ -97,7 +97,7 @@ void StylesCombo::setStylesModel(AbstractStylesModel *model)
{
m_stylesModel = model;
setModel(model);
- connect(m_stylesModel, SIGNAL(modelReset()), this, SLOT(slotModelReset()));
+// connect(m_stylesModel, SIGNAL(modelReset()), this, SLOT(slotModelReset()));
// m_view->expandAll();
}
@@ -143,16 +143,31 @@ void StylesCombo::slotSelectionChanged(int index)
m_selectedItem = index;
m_preview->setPreview(m_stylesModel->stylePreview(index, \
m_preview->availableSize())); update();
- emit selectionChanged(index);
+// emit selectionChanged(index);
}
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. +// kDebug() << "item parent: " << index.parent();
+ kDebug() << "item row: " << index.row();
+/* if (index.parent().isValid()) {
+ if (index.parent().row() == 0) {
+ m_selectedItem = index.row();
+ }
+ else if (index.parent().row() == 1) {
+ QModelIndex sibling = index.parent().sibling(0, 0);
+ m_selectedItem = sibling.model()->rowCount(sibling) + index.row();
+ }
+ }
+*/
m_selectedItem = index.row();
m_preview->setPreview(m_stylesModel->stylePreview(m_selectedItem, \
m_preview->availableSize())); +// \
m_preview->setPreview(m_stylesModel->stylePreview(index, \
m_preview->availableSize())); + m_currentIndex = index;
update();
emit selected(m_selectedItem);
+ emit selected(index);
}
void StylesCombo::slotUpdatePreview()
@@ -160,6 +175,10 @@ void StylesCombo::slotUpdatePreview()
if (!m_stylesModel) {
return;
}
+ if (m_stylesModel->stylesType() == AbstractStylesModel::CharacterStyle) {
+ kDebug() << "currentIndex: " << currentIndex();
+ }
+// m_preview->setPreview(m_stylesModel->stylePreview(m_currentIndex, \
m_preview->availableSize()));
m_preview->setPreview(m_stylesModel->stylePreview(currentIndex(), \
m_preview->availableSize())); update();
}
@@ -204,7 +223,10 @@ void StylesCombo::slotDeleteStyle(QModelIndex index)
void StylesCombo::slotModelReset()
{
- m_view->expandAll();
+ kDebug() << "model used style count: " << \
m_stylesModel->rowCount(m_stylesModel->index(0,0,QModelIndex())); + kDebug() << \
"model unused style count: " << \
m_stylesModel->rowCount(m_stylesModel->index(1,0,QModelIndex())); + \
m_view->reset(); +// m_view->expandAll();
}
void StylesCombo::showEditIcon(bool show){
diff --git a/plugins/textshape/dialogs/StylesCombo.h \
b/plugins/textshape/dialogs/StylesCombo.h index eb0e70b..b58a367 100644
--- a/plugins/textshape/dialogs/StylesCombo.h
+++ b/plugins/textshape/dialogs/StylesCombo.h
@@ -67,6 +67,7 @@ signals:
* to be noted that this signal is also emitted when an item is selected 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 selected \
again. Not even if it @@ -98,10 +99,11 @@ private slots:
private:
AbstractStylesModel *m_stylesModel;
StylesComboPreview *m_preview;
-// QListView *m_view;
- QTreeView *m_view;
+ QListView *m_view;
+// QTreeView *m_view;
int m_selectedItem;
bool m_originalStyle;
+ QModelIndex m_currentIndex;
};
#endif //STYLESCOMBO_H
diff --git a/plugins/textshape/dialogs/StylesFilteredModelBase.cpp \
b/plugins/textshape/dialogs/StylesFilteredModelBase.cpp index f448a3c..09a4636 100644
--- a/plugins/textshape/dialogs/StylesFilteredModelBase.cpp
+++ b/plugins/textshape/dialogs/StylesFilteredModelBase.cpp
@@ -121,10 +121,21 @@ QImage StylesFilteredModelBase::stylePreview(int row, QSize \
size) if (row < 0) {
return QImage();
}
+ kDebug() << "requested preview for: " << row;
+ kDebug() << "proxyToSource item: " << m_proxyToSource.at(row);
return m_sourceModel->stylePreview(m_proxyToSource.at(row), size);
}
+QImage StylesFilteredModelBase::stylePreview(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 +
+}
+
void StylesFilteredModelBase::setStylesModel(AbstractStylesModel *sourceModel)
{
if (m_sourceModel == sourceModel) {
diff --git a/plugins/textshape/dialogs/StylesFilteredModelBase.h \
b/plugins/textshape/dialogs/StylesFilteredModelBase.h index 4a81c0a..7c6d723 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 \
KoStyleThumbnailer is used.
*/
virtual QImage stylePreview(int row, QSize size = QSize());
+ virtual QImage stylePreview(QModelIndex &index, QSize size = QSize());
virtual AbstractStylesModel::Type stylesType() const;
diff --git a/plugins/textshape/dialogs/StylesModel.cpp \
b/plugins/textshape/dialogs/StylesModel.cpp index 3bab6ed..32e4b67 100644
--- a/plugins/textshape/dialogs/StylesModel.cpp
+++ b/plugins/textshape/dialogs/StylesModel.cpp
@@ -211,6 +211,7 @@ QImage StylesModel::stylePreview(int row, QSize size)
}
}
else {
+ kDebug() << "request for preview. row: " << row << " internalId: " << \
index(row).internalId(); KoCharacterStyle *usedStyle = 0;
if (index(row).internalId() == -1) {
usedStyle = static_cast<KoCharacterStyle*>(m_currentParagraphStyle);
@@ -236,6 +237,47 @@ 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 == StylesModel::ParagraphStyle) {
+ KoParagraphStyle *usedStyle = 0;
+ usedStyle = 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 = 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. + }
+ 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); + }
+ }
+ }
+ return QImage();
+}
+
void StylesModel::setStyleManager(KoStyleManager *sm)
{
if (sm == m_styleManager)
diff --git a/plugins/textshape/dialogs/StylesModel.h \
b/plugins/textshape/dialogs/StylesModel.h index c904d39..d477f3a 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 \
KoStyleThumbnailer is used.
*/
QImage stylePreview(int row, QSize size = QSize());
+ QImage stylePreview(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);
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic