1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203
|
/* This file is part of the KDE project
* Copyright (C) 2007, 2009 Thomas Zander <zander@kde.org>
* Copyright (C) 2008 Girish Ramakrishnan <girish@forwardbias.in>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public License
* along with this library; see the file COPYING.LIB. If not, write to
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#include "ParagraphBulletsNumbers.h"
#include <KoParagraphStyle.h>
#include <KoListLevelProperties.h>
#include <KDebug>
#include <KCharSelect>
#include <KDialog>
ParagraphBulletsNumbers::ParagraphBulletsNumbers(QWidget *parent)
: QWidget(parent)
{
widget.setupUi(this);
foreach(const Lists::ListStyleItem & item, Lists::genericListStyleItems())
addStyle(item);
addStyle(Lists::ListStyleItem(i18n("Custom Bullet"), KoListStyle::CustomCharItem));
m_blankCharIndex = addStyle(Lists::ListStyleItem(i18n("No Bullet"), KoListStyle::CustomCharItem));
foreach(const Lists::ListStyleItem & item, Lists::otherListStyleItems())
addStyle(item);
widget.alignment->addItem(i18nc("Automatic horizontal alignment", "Auto"));
widget.alignment->addItem(i18nc("Text alignment", "Left"));
widget.alignment->addItem(i18nc("Text alignment", "Right"));
widget.alignment->addItem(i18nc("Text alignment", "Centered"));
connect(widget.listTypes, SIGNAL(currentRowChanged(int)), this, SLOT(styleChanged(int)));
connect(widget.customCharacter, SIGNAL(clicked(bool)), this, SLOT(customCharButtonPressed()));
connect(widget.letterSynchronization, SIGNAL(toggled(bool)), widget.startValue, SLOT(setLetterSynchronization(bool)));
}
int ParagraphBulletsNumbers::addStyle(const Lists::ListStyleItem &lsi)
{
m_mapping.insert(widget.listTypes->count(), lsi.style);
widget.listTypes->addItem(lsi.name);
return widget.listTypes->count() - 1;
}
void ParagraphBulletsNumbers::setDisplay(KoParagraphStyle *style, int level)
{
KoListStyle *listStyle = style->listStyle();
widget.listPropertiesPane->setEnabled(listStyle != 0);
widget.customCharacter->setText("-");
if (listStyle == 0) {
widget.listTypes->setCurrentRow(0);
return;
}
KoListLevelProperties llp = listStyle->levelProperties(level);
m_previousLevel = llp.level();
widget.prefix->setText(llp.listItemPrefix());
widget.suffix->setText(llp.listItemSuffix());
widget.letterSynchronization->setChecked(llp.letterSynchronization());
KoListStyle::Style s = llp.style();
foreach(int row, m_mapping.keys()) {
if (m_mapping[row] == s) {
widget.listTypes->setCurrentRow(row);
break;
}
}
int align;
if (llp.alignment() == (Qt::AlignLeft | Qt::AlignAbsolute))
align = 1;
else if (llp.alignment() == (Qt::AlignRight | Qt::AlignAbsolute))
align = 2;
else if (llp.alignment() == Qt::AlignCenter)
align = 3;
else
align = 0;
widget.alignment->setCurrentIndex(align);
widget.depth->setValue(llp.level());
widget.levels->setValue(llp.displayLevel());
widget.startValue->setValue(llp.startValue());
if (s == KoListStyle::CustomCharItem)
widget.customCharacter->setText(llp.bulletCharacter());
// *** features not in GUI;
// character style
// relative bullet size (percent)
// minimum label width
}
void ParagraphBulletsNumbers::save(KoParagraphStyle *savingStyle)
{
Q_ASSERT(savingStyle);
const int currentRow = widget.listTypes->currentRow();
KoListStyle::Style style = m_mapping[currentRow];
if (style == KoListStyle::None) {
savingStyle->setListStyle(0);
return;
}
if (savingStyle->listStyle() == 0) {
KoListStyle *listStyle = new KoListStyle(savingStyle);
savingStyle->setListStyle(listStyle);
}
KoListStyle *listStyle = savingStyle->listStyle();
KoListLevelProperties llp = listStyle->levelProperties(widget.depth->value());
llp.setStyle(style);
llp.setLevel(widget.depth->value());
llp.setDisplayLevel(widget.levels->value());
llp.setStartValue(widget.startValue->value());
llp.setListItemPrefix(widget.prefix->text());
llp.setListItemSuffix(widget.suffix->text());
llp.setLetterSynchronization(widget.letterSynchronization->isVisible() && widget.letterSynchronization->isChecked());
if (style == KoListStyle::CustomCharItem)
llp.setBulletCharacter(currentRow == m_blankCharIndex ? QChar() : widget.customCharacter->text().remove('&').at(0));
Qt::Alignment align;
switch (widget.alignment->currentIndex()) {
case 0: align = Qt::AlignLeft; break;
case 1: align = Qt::AlignLeft | Qt::AlignAbsolute; break;
case 2: align = Qt::AlignRight | Qt::AlignAbsolute; break;
case 3: align = Qt::AlignCenter; break;
default:
Q_ASSERT(false);
}
llp.setAlignment(align);
if (llp.level() != m_previousLevel)
listStyle->removeLevelProperties(m_previousLevel);
listStyle->setLevelProperties(llp);
}
void ParagraphBulletsNumbers::styleChanged(int index)
{
KoListStyle::Style style = m_mapping[index];
bool showLetterSynchronization = false;
switch (style) {
case KoListStyle::SquareItem:
case KoListStyle::DiscItem:
case KoListStyle::CircleItem:
case KoListStyle::BoxItem:
case KoListStyle::CustomCharItem:
case KoListStyle::None:
widget.startValue->setCounterType(KoListStyle::DecimalItem);
widget.startValue->setValue(1);
widget.startValue->setEnabled(false);
break;
case KoListStyle::AlphaLowerItem:
case KoListStyle::UpperAlphaItem:
showLetterSynchronization = true;
// fall through
default:
widget.startValue->setEnabled(true);
widget.startValue->setCounterType(style);
int value = widget.startValue->value();
widget.startValue->setValue(value + 1);
widget.startValue->setValue(value); // surely to trigger a change event.
}
widget.customCharacter->setEnabled(style == KoListStyle::CustomCharItem && index != m_blankCharIndex);
widget.letterSynchronization->setVisible(showLetterSynchronization);
widget.listPropertiesPane->setEnabled(style != KoListStyle::None);
}
void ParagraphBulletsNumbers::customCharButtonPressed()
{
KDialog *dialog = new KDialog(this);
dialog->setModal(true);
dialog->setButtons(KDialog::Ok | KDialog::Cancel);
dialog->setDefaultButton(KDialog::Ok);
KCharSelect *kcs = new KCharSelect(dialog, 0,
KCharSelect::SearchLine | KCharSelect::FontCombo | KCharSelect::BlockCombos
| KCharSelect::CharacterTable | KCharSelect::DetailBrowser);
dialog->setMainWidget(kcs);
if (dialog->exec() == KDialog::Accepted) {
QChar character = kcs->currentChar();
widget.customCharacter->setText(character);
// also switch to the custom list style.
foreach(int row, m_mapping.keys()) {
if (m_mapping[row] == KoListStyle::CustomCharItem) {
widget.listTypes->setCurrentRow(row);
break;
}
}
}
delete dialog;
}
#include <ParagraphBulletsNumbers.moc>
|