Git commit 8199a7d09d1bd5bdeff07a7ed9ae35f6d49e58c4 by Pierre Stirnweiss. Committed on 21/03/2013 at 18:40. Pushed by pstirnweiss into branch 'textshape-stylesWidget-PierreSt'. A little further in the new Stylesmanager dialog M +2 -2 plugins/textshape/CMakeLists.txt M +5 -69 plugins/textshape/dialogs/StylesModel.cpp M +0 -17 plugins/textshape/dialogs/StylesModel.h M +46 -53 plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacin= gTab.cpp M +12 -4 plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacin= gTab.h M +171 -77 plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp M +4 -4 plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h http://commits.kde.org/calligra/8199a7d09d1bd5bdeff07a7ed9ae35f6d49e58c4 diff --git a/plugins/textshape/CMakeLists.txt b/plugins/textshape/CMakeList= s.txt index 91e5194..1c37a9c 100644 --- a/plugins/textshape/CMakeLists.txt +++ b/plugins/textshape/CMakeLists.txt @@ -68,8 +68,8 @@ SET ( textshape_SRCS dialogs/StylesFilteredModelBase.cpp dialogs/ValidParentStylesProxyModel.cpp dialogs/StylesDelegate.cpp - dialogs/StyleManager.cpp - dialogs/StyleManagerDialog.cpp +# dialogs/StyleManager.cpp +# dialogs/StyleManagerDialog.cpp dialogs/ParagraphGeneral.cpp dialogs/CharacterGeneral.cpp dialogs/CharacterHighlighting.cpp diff --git a/plugins/textshape/dialogs/StylesModel.cpp b/plugins/textshape/= dialogs/StylesModel.cpp index b09f2be..dc845a1 100644 --- a/plugins/textshape/dialogs/StylesModel.cpp +++ b/plugins/textshape/dialogs/StylesModel.cpp @@ -35,12 +35,11 @@ #include = StylesModel::StylesModel(KoStyleManager *manager, AbstractStylesModel::Typ= e modelType, QObject *parent) - : AbstractStylesModel(parent), - m_styleManager(0), - m_currentParagraphStyle(0), - m_defaultCharacterStyle(0), - m_styleMapper(new QSignalMapper(this)), - m_provideStyleNone(false) + : AbstractStylesModel(parent) + , m_styleManager(0) + , m_currentParagraphStyle(0) + , m_defaultCharacterStyle(0) + , m_styleMapper(new QSignalMapper(this)) { m_modelType =3D modelType; setStyleManager(manager); @@ -112,9 +111,6 @@ QVariant StylesModel::data(const QModelIndex &index, in= t role) const if (paragStyle) { return m_styleThumbnailer->thumbnail(paragStyle, data(inde= x, Qt::SizeHintRole).toSize()); } - if (!paragStyle && m_draftParStyleList.contains(id)) { - return m_styleThumbnailer->thumbnail(m_draftParStyleList[i= d], data(index, Qt::SizeHintRole).toSize()); - } } else { KoCharacterStyle *usedStyle =3D 0; @@ -122,9 +118,6 @@ QVariant StylesModel::data(const QModelIndex &index, in= t role) const if (usedStyle) { return m_styleThumbnailer->thumbnail(usedStyle, m_currentP= aragraphStyle, data(index, Qt::SizeHintRole).toSize()); } - if (!usedStyle && m_draftCharStyleList.contains(id)) { - return m_styleThumbnailer->thumbnail(m_draftCharStyleList[= id], m_currentParagraphStyle, data(index, Qt::SizeHintRole).toSize()); - } } break; } @@ -212,9 +205,6 @@ QImage StylesModel::stylePreview(const QModelIndex &ind= ex, QSize size) 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; @@ -222,9 +212,6 @@ QImage StylesModel::stylePreview(const QModelIndex &ind= ex, QSize size) if (usedStyle) { return m_styleThumbnailer->thumbnail(usedStyle, m_currentParag= raphStyle, size); } - if (!usedStyle && m_draftCharStyleList.contains(index.internalId()= )) { - return m_styleThumbnailer->thumbnail(m_draftCharStyleList[inde= x.internalId()],m_currentParagraphStyle, size); - } } return QImage(); } @@ -268,8 +255,6 @@ void StylesModel::addParagraphStyle(KoParagraphStyle *s= tyle) int index =3D 0; for ( ; begin !=3D m_styleList.end(); ++begin) { KoParagraphStyle *s =3D m_styleManager->paragraphStyle(*begin);; - if (!s && m_draftParStyleList.contains(*begin)) - s =3D m_draftParStyleList[*begin]; // s should be found as the manager and the m_styleList should be = in sync Q_ASSERT(s); if (KStringHandler::naturalCompare(style->name(),s->name()) < 0) { @@ -321,8 +306,6 @@ void StylesModel::addCharacterStyle(KoCharacterStyle *s= tyle) int index =3D 0; for ( ; begin !=3D m_styleList.end(); ++begin) { KoCharacterStyle *s =3D m_styleManager->characterStyle(*begin);; - if (!s && m_draftCharStyleList.contains(*begin)) - s =3D m_draftCharStyleList[*begin]; // s should be found as the manager and the m_styleList should be = in sync Q_ASSERT(s); if (KStringHandler::naturalCompare(style->name(),s->name()) < 0) { @@ -395,8 +378,6 @@ void StylesModel::updateName(int styleId) int newIndex =3D 0; if (m_modelType =3D=3D StylesModel::ParagraphStyle) { KoParagraphStyle *paragStyle =3D m_styleManager->paragraphStyl= e(styleId); - if (!paragStyle && m_draftParStyleList.contains(styleId)) - paragStyle =3D m_draftParStyleList.value(styleId); if (paragStyle) { m_styleThumbnailer->removeFromCache(paragStyle); = @@ -407,8 +388,6 @@ void StylesModel::updateName(int styleId) continue; } KoParagraphStyle *s =3D m_styleManager->paragraphStyle= (*begin); - if (!s && m_draftParStyleList.contains(*begin)) - s =3D m_draftParStyleList[*begin]; // s should be found as the manager and the m_styleLis= t should be in sync Q_ASSERT(s); if (KStringHandler::naturalCompare(paragStyle->name(),= s->name()) < 0) { @@ -428,8 +407,6 @@ void StylesModel::updateName(int styleId) } else { KoCharacterStyle *characterStyle =3D m_styleManager->character= Style(styleId); - if (!characterStyle && m_draftCharStyleList.contains(styleId)) - characterStyle =3D m_draftCharStyleList[styleId]; if (characterStyle) { m_styleThumbnailer->removeFromCache(characterStyle); = @@ -440,8 +417,6 @@ void StylesModel::updateName(int styleId) continue; } KoCharacterStyle *s =3D m_styleManager->characterStyle= (*begin); - if (!s && m_draftCharStyleList.contains(*begin)) - s =3D m_draftCharStyleList[*begin]; // s should be found as the manager and the m_styleLis= t should be in sync Q_ASSERT(s); if (KStringHandler::naturalCompare(characterStyle->nam= e(), s->name()) < 0) { @@ -475,45 +450,6 @@ QList StylesModel::StyleList() return m_styleList; } = -QHash StylesModel::draftParStyleList() -{ - return m_draftParStyleList; -} - -QHash StylesModel::draftCharStyleList() -{ - return m_draftCharStyleList; -} - -void StylesModel::addDraftParagraphStyle(KoParagraphStyle *style) -{ - style->setStyleId(-(m_draftParStyleList.count()+1)); - m_draftParStyleList.insert(style->styleId(), style); - addParagraphStyle(style); -} - -void StylesModel::addDraftCharacterStyle(KoCharacterStyle *style) -{ - if (m_draftCharStyleList.count() =3D=3D 0) // we have a character styl= e "m_defaultCharacterStyle" with style id -1 in style model. - style->setStyleId(-(m_draftCharStyleList.count()+2)); - else - style->setStyleId(-(m_draftCharStyleList.count()+1)); - m_draftCharStyleList.insert(style->styleId(), style); - addCharacterStyle(style); -} - -void StylesModel::clearDraftStyles() -{ - foreach(KoParagraphStyle *style, m_draftParStyleList.values()) { - removeParagraphStyle(style); - } - m_draftParStyleList.clear(); - foreach(KoCharacterStyle *style, m_draftCharStyleList.values()) { - removeCharacterStyle(style); - } - m_draftCharStyleList.clear(); -} - StylesModel::Type StylesModel::stylesType() const { return m_modelType; diff --git a/plugins/textshape/dialogs/StylesModel.h b/plugins/textshape/di= alogs/StylesModel.h index d078b5f..bce1c5f 100644 --- a/plugins/textshape/dialogs/StylesModel.h +++ b/plugins/textshape/dialogs/StylesModel.h @@ -108,19 +108,6 @@ public: /** Return style id list. */ QList StyleList(); = - /** Return new styles and their ids. */ - QHash draftParStyleList(); - QHash draftCharStyleList(); - - /** Add a paragraph style to pargraph style list but this style is not= applied. */ - void addDraftParagraphStyle(KoParagraphStyle *style); - - /** Add a character style to character style list but this style is no= t applied. */ - void addDraftCharacterStyle(KoCharacterStyle *style); - - /** we call this when we apply our unapplied styles and we clear our l= ist. */ - void clearDraftStyles(); - /** We call this when we want a clear style model. */ void clearStyleModel(); = @@ -143,8 +130,6 @@ private: = protected: QList m_styleList; // list of style IDs - QHash m_draftParStyleList; // list of new sty= les that are not applied - QHash m_draftCharStyleList; = private: KoStyleManager *m_styleManager; @@ -153,8 +138,6 @@ private: KoCharacterStyle *m_defaultCharacterStyle; = QSignalMapper *m_styleMapper; - - bool m_provideStyleNone; }; = #endif diff --git a/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingT= ab.cpp b/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingTab.c= pp index cb9a38f..76ebdc3 100644 --- a/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingTab.cpp +++ b/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingTab.cpp @@ -116,75 +116,66 @@ void ParagraphIndentSpacingTab::slotLineSpacingEnable= d(bool enabled) { ui->lineSpacing->setEnabled(enabled); ui->spacingStack->setEnabled(enabled); - ui->useFont->setEnabled(enabled); + ui->useFont->setEnabled(enabled && ui->lineSpacing->currentIndex() != =3D 5); emit lineSpacingEnabled(enabled); } = void ParagraphIndentSpacingTab::slotLineSpacingChanged(int item) { - emit lineSpacingChanged(item); -//this does not belong here -/* bool percent =3D false, custom =3D false; - qreal customValue =3D 0.0; + kDebug() << "slot line spacing changed."; + kDebug() << "item: " << item; + kDebug() << "useFont: " << ui->useFont->isChecked(); + kDebug() << "proportional value: " << ui->proportional->value(); + kDebug() << "custom value: " << ui->custom->value(); switch (item) { - case 0: - case 1: - case 2: - break; - case 3: // proportional - percent =3D true; - ui->proportional->setValue(m_style->lineHeightPercent()); - break; - case 4: // additional - custom =3D true; - customValue =3D qMax(qreal(0.1), m_style->lineSpacing()); - break; - case 5: // fixed - custom =3D true; - if (m_style->lineHeightAbsolute() =3D=3D 0) // unset - customValue =3D 12.0; // nice default value... - else - customValue =3D m_style->lineHeightAbsolute(); - break; - case 6: // minimum - custom =3D true; - customValue =3D m_style->minimumLineHeight(); - break; - default:; // other cases don't need the spinboxes - } - - m_spacingInherited =3D false; - - if (custom) { - ui->custom->setEnabled(true); - ui->spacingStack->setCurrentWidget(ui->unitsPage); - ui->custom->changeValue(customValue); - } else { - ui->spacingStack->setCurrentWidget(ui->percentPage); - ui->proportional->setEnabled(percent); - if (! percent) - ui->proportional->setValue(100); + case 0: + emit lineSpacingChanged(LineHeightProportional, 120, ui->useFont->= isChecked()); + break; + case 1: + emit lineSpacingChanged(LineHeightProportional, 180, ui->useFont->= isChecked()); + break; + case 2: + emit lineSpacingChanged(LineHeightProportional, 240, ui->useFont->= isChecked()); + break; + case 3: + emit lineSpacingChanged(LineHeightProportional, ui->proportional->= value(), ui->useFont->isChecked()); + break; + case 4: + if (ui->custom->value() =3D=3D 0.0) { + emit lineSpacingChanged(LineHeightProportional, 100, ui->useFo= nt->isChecked()); //we need to save it as percentage + } + else { + emit lineSpacingChanged(LineSpacingAdditional, ui->custom->val= ue(), ui->useFont->isChecked()); + } + break; + case 5: + emit lineSpacingChanged(LineHeightFixed, ui->custom->value(), fals= e); + break; + case 6: + emit lineSpacingChanged(LineHeightMinimum, ui->custom->value(), ui= ->useFont->isChecked()); + break; } - - ui->useFont->setEnabled(item !=3D 5); - ui->useFont->setChecked(item =3D=3D 5 ? false : m_fontMetricsChecked); - emit parStyleChanged(); -*/ } = void ParagraphIndentSpacingTab::slotLineSpacingPercentChanged(int percent) { - emit lineSpacingPercentChanged(percent); + Q_UNUSED(percent); + slotLineSpacingChanged(ui->lineSpacing->currentIndex()); +// emit lineSpacingPercentChanged(percent); } = void ParagraphIndentSpacingTab::slotLineSpacingValueChanged(qreal value) { - emit lineSpacingValueChanged(value); + Q_UNUSED(value); + slotLineSpacingChanged(ui->lineSpacing->currentIndex()); +// emit lineSpacingValueChanged(value); } = void ParagraphIndentSpacingTab::slotUseFontMetricsChecked(bool checked) { - emit useFontMetricsChecked(checked); + Q_UNUSED(checked); + slotLineSpacingChanged(ui->lineSpacing->currentIndex()); +// emit useFontMetricsChecked(checked); } = void ParagraphIndentSpacingTab::slotTopParagraphSpacingEnabled(bool enable= d) @@ -232,9 +223,6 @@ void ParagraphIndentSpacingTab::setDisplay(KoParagraphS= tyle *style) ui->first->changeValue(style->textIndent()); = //line spacing - checked =3D (style->hasProperty(KoParagraphStyle::FixedLineHeight) || = style->hasProperty(KoParagraphStyle::LineSpacing) || style->hasProperty(KoP= aragraphStyle::PercentLineHeight) ||style->hasProperty(KoParagraphStyle::Mi= nimumLineHeight)); - ui->lineSpacingLabel->setChecked(checked); - slotLineSpacingEnabled(checked); ui->proportional->setValue(style->lineHeightPercent()); = if (style->hasProperty(KoParagraphStyle::FixedLineHeight) && style->li= neHeightAbsolute() !=3D 0) { @@ -279,6 +267,11 @@ void ParagraphIndentSpacingTab::setDisplay(KoParagraph= Style *style) ui->useFont->setChecked(style->lineSpacingFromFont() && ui->lineSpacin= g->currentIndex() !=3D 5); m_fontMetricsChecked =3D style->lineSpacingFromFont(); = + checked =3D (style->hasProperty(KoParagraphStyle::FixedLineHeight) || = style->hasProperty(KoParagraphStyle::LineSpacing) || style->hasProperty(KoP= aragraphStyle::PercentLineHeight) ||style->hasProperty(KoParagraphStyle::Mi= nimumLineHeight)); + ui->lineSpacingLabel->setChecked(checked); + slotLineSpacingEnabled(checked); //we do this after setting the line s= pacing widgets because the useFontMetrics check box enabling depends on the= line spacing type + + //paragraph spacing checked =3D style->hasProperty(QTextFormat::BlockTopMargin); ui->beforeLabel->setChecked(checked); diff --git a/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingT= ab.h b/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingTab.h index e5305a5..923d97f 100644 --- a/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingTab.h +++ b/plugins/textshape/dialogs/stylemanager/ParagraphIndentSpacingTab.h @@ -34,6 +34,13 @@ class ParagraphIndentSpacingTab : public QWidget { Q_OBJECT public: + enum LineSpacingType { + LineHeightProportional, + LineHeightFixed, + LineHeightMinimum, + LineSpacingAdditional + }; + explicit ParagraphIndentSpacingTab(QWidget *parent =3D 0); ~ParagraphIndentSpacingTab(); // open and display the style @@ -53,11 +60,12 @@ signals: void firstLineIndentChanged(qreal value); void autoTextIndentChecked(bool checked); //line spacing signals + void lineSpacingChanged(ParagraphIndentSpacingTab::LineSpacingType spa= cingType, qreal value, bool useFontMetrics); void lineSpacingEnabled(bool enabled); - void lineSpacingChanged(int item); - void lineSpacingValueChanged(qreal value); - void lineSpacingPercentChanged(int percent); - void useFontMetricsChecked(bool checked); +// void lineSpacingChanged(int item); +// void lineSpacingValueChanged(qreal value); +// void lineSpacingPercentChanged(int percent); +// void useFontMetricsChecked(bool checked); //paragraph spacing signals void topParagraphSpacingEnabled(bool enabled); void topParagraphSpacingChanged(qreal value); diff --git a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp = b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp index 321b8a3..20e0449 100644 --- a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp +++ b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.cpp @@ -73,10 +73,7 @@ ParagraphStylesTab::ParagraphStylesTab(QWidget *parent) : connect(ui->indentSpacing, SIGNAL(firstLineIndentChanged(qreal)), this= , SLOT(slotFirstLineIndentChanged(qreal))); connect(ui->indentSpacing, SIGNAL(autoTextIndentChecked(bool)), this, = SLOT(slotAutoTextIndentChecked(bool))); connect(ui->indentSpacing, SIGNAL(lineSpacingEnabled(bool)), this, SLO= T(slotLineSpacingEnabled(bool))); - connect(ui->indentSpacing, SIGNAL(lineSpacingChanged(int)), this, SLOT= (slotLineSpacingChanged(int))); - connect(ui->indentSpacing, SIGNAL(lineSpacingValueChanged(qreal)), thi= s, SLOT(slotLineSpacingValueChanged(qreal))); - connect(ui->indentSpacing, SIGNAL(lineSpacingPercentChanged(int)), thi= s, SLOT(slotLineSpacingPercentChanged(int))); - connect(ui->indentSpacing, SIGNAL(useFontMetricsChecked(bool)), this, = SLOT(slotUseFontMetricsChecked(bool))); + connect(ui->indentSpacing, SIGNAL(lineSpacingChanged(ParagraphIndentSp= acingTab::LineSpacingType,qreal,bool)), this, SLOT(slotLineSpacingChanged(P= aragraphIndentSpacingTab::LineSpacingType,qreal,bool))); connect(ui->indentSpacing, SIGNAL(topParagraphSpacingEnabled(bool)), t= his, SLOT(slotTopParagraphSpacingEnabled(bool))); connect(ui->indentSpacing, SIGNAL(topParagraphSpacingChanged(qreal)), = this, SLOT(slotTopParagraphSpacingChanged(qreal))); connect(ui->indentSpacing, SIGNAL(bottomParagraphSpacingEnabled(bool))= , this, SLOT(slotBottomParagraphSpacingEnabled(bool))); @@ -91,6 +88,7 @@ ParagraphStylesTab::~ParagraphStylesTab() = void ParagraphStylesTab::setDisplay(KoParagraphStyle *style) { + ui->paragraphListView->update(ui->paragraphListView->currentIndex()); ui->characterHighlighting->setDisplay(style); ui->indentSpacing->setDisplay(style); } @@ -117,8 +115,7 @@ void ParagraphStylesTab::slotStyleSelected(const QModel= Index &index) { KoParagraphStyle *style =3D static_cast(index.data(= AbstractStylesModel::ParagraphStylePointer).value()); if (style) { - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -127,8 +124,7 @@ void ParagraphStylesTab::slotCreateNewStyle() KoParagraphStyle *newStyle =3D dynamic_cast(m_parag= raphStylesModel->slotCreateNewStyle(ui->paragraphListView->currentIndex())); if (newStyle) { ui->paragraphListView->setCurrentIndex(m_paragraphStylesModel->ind= exForCharacterStyle(*newStyle)); - ui->characterHighlighting->setDisplay(newStyle); - ui->indentSpacing->setDisplay(newStyle); + setDisplay(newStyle); } = } @@ -143,6 +139,8 @@ void ParagraphStylesTab::slotSaveStyle() //TODO reselec= t the style, create a sav } = /*TODOs: +- inherit style on new style instead of cloning +- create our own KFontChooser. the stock kde one does not allow to disable= individual font properties */ = /// ///////////////////CharacterHighlightingTab slots @@ -157,9 +155,8 @@ void ParagraphStylesTab::slotCapitalizationEnabled(bool= enabled) else if (!enabled && style->KoCharacterStyle::hasProperty(QTextFor= mat::FontCapitalization)) { style->KoCharacterStyle::remove(QTextFormat::FontCapitalizatio= n); } - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + + setDisplay(style); } } = @@ -169,9 +166,7 @@ void ParagraphStylesTab::slotCapitalizationChanged(QFon= t::Capitalization capital if (style) { style->KoCharacterStyle::setFontCapitalization(capitalization); = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -190,9 +185,7 @@ void ParagraphStylesTab::slotUnderlineEnabled(bool enab= led) style->KoCharacterStyle::remove(QTextFormat::TextUnderlineColo= r); } = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -204,9 +197,7 @@ void ParagraphStylesTab::slotUnderlineChanged(KoCharact= erStyle::LineType lineTyp style->KoCharacterStyle::setUnderlineStyle(lineStyle); style->KoCharacterStyle::setUnderlineColor(lineColor); = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -225,9 +216,7 @@ void ParagraphStylesTab::slotStrikethroughEnabled(bool = enabled) style->KoCharacterStyle::remove(KoCharacterStyle::StrikeOutCol= or); } = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -239,9 +228,7 @@ void ParagraphStylesTab::slotStrikethroughChanged(KoCha= racterStyle::LineType lin style->KoCharacterStyle::setStrikeOutStyle(lineStyle); style->KoCharacterStyle::setStrikeOutColor(lineColor); = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -255,9 +242,8 @@ void ParagraphStylesTab::slotPositionEnabled(bool enabl= ed) else if (!enabled && style->KoCharacterStyle::hasProperty(QTextFor= mat::TextVerticalAlignment)) { style->KoCharacterStyle::remove(QTextFormat::TextVerticalAlign= ment); } - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + + setDisplay(style); } } = @@ -267,9 +253,7 @@ void ParagraphStylesTab::slotPositionChanged(QTextCharF= ormat::VerticalAlignment if (style) { style->KoCharacterStyle::setVerticalAlignment(alignment); = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -283,9 +267,8 @@ void ParagraphStylesTab::slotBackgroundColorEnabled(boo= l enabled) else if (!enabled && style->KoCharacterStyle::hasProperty(QTextFor= mat::BackgroundBrush)) { style->KoCharacterStyle::remove(QTextFormat::BackgroundBrush); } - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + + setDisplay(style); } } = @@ -295,9 +278,7 @@ void ParagraphStylesTab::slotBackgroundColorChanged(con= st QColor color) if (style) { style->KoCharacterStyle::setBackground(QBrush(color)); = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -311,9 +292,8 @@ void ParagraphStylesTab::slotTextColorEnabled(bool enab= led) else if (!enabled && style->KoCharacterStyle::hasProperty(QTextFor= mat::ForegroundBrush)) { style->KoCharacterStyle::remove(QTextFormat::ForegroundBrush); } - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + + setDisplay(style); } } = @@ -323,9 +303,7 @@ void ParagraphStylesTab::slotTextColorChanged(QColor co= lor) if (style) { style->KoCharacterStyle::setForeground(QBrush(color)); = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -346,9 +324,7 @@ void ParagraphStylesTab::slotFontEnabled(bool enabled) style->KoCharacterStyle::remove(QTextFormat::FontPointSize); } = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -361,9 +337,7 @@ void ParagraphStylesTab::slotFontChanged(const QFont &f= ont) style->KoCharacterStyle::setFontWeight(font.weight()); style->KoCharacterStyle::setFontPointSize(font.pointSize()); = - ui->paragraphListView->update(ui->paragraphListView->currentIndex(= )); - ui->characterHighlighting->setDisplay(style); - ui->indentSpacing->setDisplay(style); + setDisplay(style); } } = @@ -372,82 +346,202 @@ void ParagraphStylesTab::slotFontChanged(const QFont= &font) //indentation slots void ParagraphStylesTab::slotLeftIndentEnabled(bool enabled) { - kDebug() << "leftIndent enabled: " << enabled; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + if (enabled && !style->hasProperty(QTextFormat::BlockLeftMargin)) { + style->setLeftMargin(QTextLength(QTextLength::FixedLength, sty= le->leftMargin())); //set the left margin of the parent/default paragraph s= tyle. If none exists, 0 is returned. + } + else if (!enabled && style->hasProperty(QTextFormat::BlockLeftMarg= in)) { + style->remove(QTextFormat::BlockLeftMargin); + } + + setDisplay(style); + } } = void ParagraphStylesTab::slotLeftIndentChanged(qreal value) { - kDebug() << "new value: " << value; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + style->setLeftMargin(QTextLength(QTextLength::FixedLength, value)); + + setDisplay(style); + } } = void ParagraphStylesTab::slotRightIndentEnabled(bool enabled) { - kDebug() << "rightIndent enabled: " << enabled; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + if (enabled && !style->hasProperty(QTextFormat::BlockRightMargin))= { + style->setRightMargin(QTextLength(QTextLength::FixedLength, st= yle->rightMargin())); //set the right margin of the parent/default paragrap= h style. If none exists, 0 is returned. + } + else if (!enabled && style->hasProperty(QTextFormat::BlockRightMar= gin)) { + style->remove(QTextFormat::BlockRightMargin); + } + + setDisplay(style); + } } = void ParagraphStylesTab::slotRightIndentChanged(qreal value) { - kDebug() << "new value: " << value; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + style->setRightMargin(QTextLength(QTextLength::FixedLength, value)= ); + + setDisplay(style); + } } = void ParagraphStylesTab::slotFirstLineIndentEnabled(bool enabled) { - kDebug() << "firstLineIndent enabled: " << enabled; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + if (enabled && !style->hasProperty(QTextFormat::TextIndent)) { + style->setTextIndent(QTextLength(QTextLength::FixedLength, sty= le->textIndent())); //set the first line indent of the parent/default parag= raph style. If none exists, 0 is returned. + } + else if (!enabled && style->hasProperty(QTextFormat::TextIndent)) { + style->remove(QTextFormat::TextIndent); + } + + setDisplay(style); + } } = void ParagraphStylesTab::slotFirstLineIndentChanged(qreal value) { - kDebug() << "new value: " << value; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + style->setTextIndent(QTextLength(QTextLength::FixedLength, value)); + + setDisplay(style); + } } = void ParagraphStylesTab::slotAutoTextIndentChecked(bool checked) { - kDebug() << "checked: " << checked; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + style->setAutoTextIndent(checked); + + setDisplay(style); + } } = //line spacing slots void ParagraphStylesTab::slotLineSpacingEnabled(bool enabled) { - kDebug() << "leftSpacing enabled: " << enabled; -} - -void ParagraphStylesTab::slotLineSpacingChanged(int item) -{ - kDebug() << "selected item: " << item; -} + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + if (enabled && (!style->hasProperty(KoParagraphStyle::FixedLineHei= ght) || !style->hasProperty(KoParagraphStyle::LineSpacing) || !style->hasPr= operty(KoParagraphStyle::PercentLineHeight) || !style->hasProperty(KoParagr= aphStyle::MinimumLineHeight))) { + style->setLineHeightAbsolute(style->lineHeightAbsolute()); + style->setLineHeightPercent(style->lineHeightPercent()); + style->setLineSpacing(style->lineSpacing()); + style->setMinimumLineHeight(QTextLength(QTextLength::FixedLeng= th, style->minimumLineHeight())); + style->setLineSpacingFromFont(style->lineSpacingFromFont()); + } + else if (!enabled && (style->hasProperty(KoParagraphStyle::FixedLi= neHeight) || style->hasProperty(KoParagraphStyle::LineSpacing) || style->ha= sProperty(KoParagraphStyle::PercentLineHeight) || style->hasProperty(KoPara= graphStyle::MinimumLineHeight))) { + style->remove(KoParagraphStyle::FixedLineHeight); + style->remove(KoParagraphStyle::LineSpacing); + style->remove(KoParagraphStyle::PercentLineHeight); + style->remove(KoParagraphStyle::MinimumLineHeight); + } = -void ParagraphStylesTab::slotLineSpacingValueChanged(qreal value) -{ - kDebug() << "new value: " << value; + setDisplay(style); + } } = -void ParagraphStylesTab::slotLineSpacingPercentChanged(int percent) +void ParagraphStylesTab::slotLineSpacingChanged(ParagraphIndentSpacingTab:= :LineSpacingType spacingType, qreal value, bool useFontMetrics) { - kDebug() << "percent: " << percent; -} + kDebug() << "slot lineSpacing changed"; + kDebug() << "spacing type: " << spacingType; + kDebug() << "value: " << value; + kDebug() << "useFont: " << useFontMetrics; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + switch (spacingType) { + case ParagraphIndentSpacingTab::LineHeightProportional: + style->setLineHeightAbsolute(0); // since it trumps percentage= based line heights, unset it. + style->setMinimumLineHeight(QTextLength(QTextLength::FixedLeng= th, 0)); + style->setLineSpacing(0); + style->setLineHeightPercent(int(value)); + style->setLineSpacingFromFont(useFontMetrics); + break; + case ParagraphIndentSpacingTab::LineSpacingAdditional: + style->setLineHeightAbsolute(0); // since it trumps percentage= based line heights, unset it. + style->setMinimumLineHeight(QTextLength(QTextLength::FixedLeng= th, 0)); + style->setLineSpacing(value); + style->setLineHeightPercent(100); + style->setLineSpacingFromFont(useFontMetrics); + break; + case ParagraphIndentSpacingTab::LineHeightFixed: + style->setMinimumLineHeight(QTextLength(QTextLength::FixedLeng= th, 0)); + style->setLineSpacing(0); + style->setLineHeightPercent(100); + style->setLineHeightAbsolute(style->lineHeightAbsolute()); + style->setLineSpacingFromFont(false); + break; + case ParagraphIndentSpacingTab::LineHeightMinimum: + style->setLineHeightAbsolute(0); // since it trumps percentage= based line heights, unset it. + style->setLineHeightPercent(100); + style->setLineSpacing(0); + style->setMinimumLineHeight(QTextLength(QTextLength::FixedLeng= th, style->minimumLineHeight())); + style->setLineSpacingFromFont(false); + break; + } = -void ParagraphStylesTab::slotUseFontMetricsChecked(bool checked) -{ - kDebug() << "checked: " << checked; + setDisplay(style); + } } = //paragraph spacing slots void ParagraphStylesTab::slotTopParagraphSpacingEnabled(bool enabled) { - kDebug() << "topSpacing enabled: " << enabled; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + if (enabled && !style->hasProperty(QTextFormat::BlockTopMargin)) { + style->setTopMargin(QTextLength(QTextLength::FixedLength, styl= e->topMargin())); + } + else if (!enabled && style->hasProperty(QTextFormat::BlockTopMargi= n)) { + style->remove(QTextFormat::BlockTopMargin); + } + + setDisplay(style); + } } = void ParagraphStylesTab::slotTopParagraphSpacingChanged(qreal value) { - kDebug() << "new value: " << value; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + style->setTopMargin(QTextLength(QTextLength::FixedLength, value)); + + setDisplay(style); + } } = void ParagraphStylesTab::slotBottomParagraphSpacingEnabled(bool enabled) { - kDebug() << "bottomSpacing enabled: " << enabled; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + if (enabled && !style->hasProperty(QTextFormat::BlockBottomMargin)= ) { + style->setBottomMargin(QTextLength(QTextLength::FixedLength, s= tyle->bottomMargin())); + } + else if (!enabled && style->hasProperty(QTextFormat::BlockBottomMa= rgin)) { + style->remove(QTextFormat::BlockBottomMargin); + } + + setDisplay(style); + } } = void ParagraphStylesTab::slotBottomParagraphSpacingChanged(qreal value) { - kDebug() << "new value: " << value; + KoParagraphStyle *style =3D dynamic_cast(m_paragrap= hStylesModel->unsavedStyle(ui->paragraphListView->currentIndex())); + if (style) { + style->setBottomMargin(QTextLength(QTextLength::FixedLength, value= )); + + setDisplay(style); + } } diff --git a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h b/= plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h index 74a2212..df6b406 100644 --- a/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h +++ b/plugins/textshape/dialogs/stylemanager/ParagraphStylesTab.h @@ -20,6 +20,8 @@ #ifndef PARAGRAPHSTYLESTAB_H #define PARAGRAPHSTYLESTAB_H = +#include "ParagraphIndentSpacingTab.h" + #include #include = @@ -53,6 +55,7 @@ private slots: void slotCreateNewStyle(); void slotSaveStyle(); = + //character highlighting slots void slotCapitalizationEnabled(bool enabled); void slotCapitalizationChanged(QFont::Capitalization capitalization); void slotUnderlineEnabled(bool enabled); @@ -78,10 +81,7 @@ private slots: void slotAutoTextIndentChecked(bool checked); //line spacing slots void slotLineSpacingEnabled(bool enabled); - void slotLineSpacingChanged(int item); - void slotLineSpacingValueChanged(qreal value); - void slotLineSpacingPercentChanged(int percent); - void slotUseFontMetricsChecked(bool checked); + void slotLineSpacingChanged(ParagraphIndentSpacingTab::LineSpacingType= spacingType, qreal value, bool useFontMetrics); //paragraph spacing slots void slotTopParagraphSpacingEnabled(bool enabled); void slotTopParagraphSpacingChanged(qreal value);