Commit f00f7d95 authored by Gopalakrishna Bhat A's avatar Gopalakrishna Bhat A

Add UI to change the list level. The buttons for adding the numbered and...

Add UI to change the list level. The buttons for adding the numbered and unnumbered lists has been merged

REVIEW: 104022
parent b617b09a
......@@ -177,26 +177,26 @@ QList<ListStyleItem> Lists::genericListStyleItems()
{
QList<ListStyleItem> answer;
answer.append(ListStyleItem(i18nc("Text list-style", "None"), KoListStyle::None));
answer.append(ListStyleItem(i18n("Arabic"), KoListStyle::DecimalItem));
answer.append(ListStyleItem(i18n("Lower Alphabetical"), KoListStyle::AlphaLowerItem));
answer.append(ListStyleItem(i18n("Upper Alphabetical"), KoListStyle::UpperAlphaItem));
answer.append(ListStyleItem(i18n("Lower Roman"), KoListStyle::RomanLowerItem));
answer.append(ListStyleItem(i18n("Upper Roman"), KoListStyle::UpperRomanItem));
answer.append(ListStyleItem(i18n("Small Bullet"), KoListStyle::Bullet));
answer.append(ListStyleItem(i18n("Large Bullet"), KoListStyle::BlackCircle));
answer.append(ListStyleItem(i18n("Circle Bullet"), KoListStyle::CircleItem));
answer.append(ListStyleItem(i18n("Square Bullet"), KoListStyle::SquareItem));
answer.append(ListStyleItem(i18n("Rhombus Bullet"), KoListStyle::RhombusItem));
answer.append(ListStyleItem(i18n("Check Mark Bullet"), KoListStyle::HeavyCheckMarkItem));
answer.append(ListStyleItem(i18n("Ballot X Bullet"), KoListStyle::BallotXItem));
answer.append(ListStyleItem(i18n("Rightwards Arrow Bullet"), KoListStyle::RightArrowItem));
answer.append(ListStyleItem(i18n("Rightwards Arrow Head Bullet"), KoListStyle::RightArrowHeadItem));
answer.append(ListStyleItem(i18n("Arabic"), KoListStyle::DecimalItem));
answer.append(ListStyleItem(i18n("Lower Alphabetical"), KoListStyle::AlphaLowerItem));
answer.append(ListStyleItem(i18n("Upper Alphabetical"), KoListStyle::UpperAlphaItem));
answer.append(ListStyleItem(i18n("Lower Roman"), KoListStyle::RomanLowerItem));
answer.append(ListStyleItem(i18n("Upper Roman"), KoListStyle::UpperRomanItem));
return answer;
}
QList<ListStyleItem> Lists::otherListStyleItems()
{
QList<ListStyleItem> answer;
answer.append(ListStyleItem(i18n("Large Bullet"), KoListStyle::BlackCircle));
answer.append(ListStyleItem(i18n("Ballot X Bullet"), KoListStyle::BallotXItem));
answer.append(ListStyleItem(i18n("Rightwards Arrow Head Bullet"), KoListStyle::RightArrowHeadItem));
answer.append(ListStyleItem(i18n("Bengali"), KoListStyle::Bengali));
answer.append(ListStyleItem(i18n("Gujarati"), KoListStyle::Gujarati));
answer.append(ListStyleItem(i18n("Gurumukhi"), KoListStyle::Gurumukhi));
......
......@@ -84,6 +84,7 @@ SET ( textshape_SRCS
dialogs/TableOfContentsEntryDelegate.cpp
dialogs/TableOfContentsEntryModel.cpp
dialogs/TableOfContentsTemplate.cpp
dialogs/ListLevelChooser.cpp
commands/ChangeListLevelCommand.cpp
commands/TextCutCommand.cpp
......
......@@ -2326,4 +2326,19 @@ void TextTool::textDirectionChanged()
m_textEditor.data()->mergeBlockFormat(blockFormat);
}
void TextTool::setListLevel(int level)
{
if (level < 1 || level > 10) {
return;
}
KoTextEditor *textEditor = m_textEditor.data();
if (textEditor->block().textList()) {
ChangeListLevelCommand::CommandType type = ChangeListLevelCommand::SetLevel;
ChangeListLevelCommand *cll = new ChangeListLevelCommand(*textEditor->cursor(), type, level);
textEditor->addCommand(cll);
editingPluginEvents();
}
}
#include <TextTool.moc>
......@@ -244,6 +244,8 @@ private slots:
void setStyle(KoParagraphStyle *syle);
/// set the characterStyle of the current selection. see above.
void setStyle(KoCharacterStyle *style);
/// set the level of current selected list
void setListLevel(int level);
/// slot to call when a series of commands is started that together need to become 1 undo action.
void startMacro(const QString &title);
......
......@@ -72,7 +72,7 @@ int ChangeListLevelCommand::effectiveLevel(int level)
} else if (m_type == DecreaseLevel) {
result = level - m_coefficient;
} else if (m_type == SetLevel) {
result = level;
result = m_coefficient;
}
result = qMax(1, qMin(10, result));
return result;
......@@ -90,7 +90,7 @@ void ChangeListLevelCommand::redo()
}
}
else {
for (int i = 0; i < m_blocks.size(); ++i) {
for (int i = 0; i < m_blocks.size() && m_lists.value(i); ++i) {
if (!m_lists.value(i)->style()->hasLevelProperties(m_levels.value(i))) {
KoListLevelProperties llp = m_lists.value(i)->style()->levelProperties(m_levels.value(i));
llp.setIndent((m_levels.value(i)-1) * 20); //TODO make this configurable
......
/* This file is part of the KDE project
* Copyright (C) 2012 Gopalakrishna Bhat A <gopalakbhat@gmail.com>
*
* 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 "ListLevelChooser.h"
#include <QPushButton>
#include <QPainter>
#include <QDebug>
ListLevelChooser::ListLevelChooser(const int offset, QWidget *parent):
QPushButton("", parent),
m_offset(offset)
{
setFlat(true);
setMinimumSize(QSize(256, 20));
}
void ListLevelChooser::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QPushButton::paintEvent(event);
QPainter painter(this);
painter.save();
painter.setPen(QPen(painter.pen().brush(), 1, Qt::DashLine, Qt::RoundCap, Qt::RoundJoin));
QRect rectang = rect();
//painter.fillRect(rectang, QBrush(QColor(Qt::white)));
painter.translate(m_offset, 1.5);
painter.setRenderHint(QPainter::Antialiasing);
painter.drawText(rectang, Qt::AlignVCenter, QString::fromUtf8("●"));
int lineY = rectang.y() + (rectang.height() / 2);
painter.drawLine(13, lineY, rectang.bottomRight().x() - m_offset- 15, lineY);
painter.restore();
}
/* This file is part of the KDE project
* Copyright (C) 2012 Gopalakrishna Bhat A <gopalakbhat@gmail.com>
*
* 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.
*/
#ifndef LISTLEVELCHOOSER_H
#define LISTLEVELCHOOSER_H
#include <QWidget>
#include <QPushButton>
class ListLevelChooser : public QPushButton
{
Q_OBJECT
public:
explicit ListLevelChooser(const int offset, QWidget *parent = 0);
protected:
void paintEvent(QPaintEvent *event);
private:
int m_offset;
};
#endif // LISTLEVELCHOOSER_H
......@@ -28,6 +28,8 @@
#include "StylesCombo.h"
#include "StylesModel.h"
#include "StylesDelegate.h"
#include "ListLevelChooser.h"
#include "commands/ChangeListLevelCommand.h"
#include <KoTextBlockData.h>
#include <KoParagraphStyle.h>
......@@ -42,6 +44,9 @@
#include <QTextLayout>
#include <QFlags>
#include <QMenu>
#include <QWidgetAction>
#include <QSignalMapper>
#include <KDebug>
......@@ -52,7 +57,8 @@ SimpleParagraphWidget::SimpleParagraphWidget(TextTool *tool, QWidget *parent)
m_tool(tool),
m_directionButtonState(Auto),
m_thumbnailer(new KoStyleThumbnailer()),
m_stylesModel(new StylesModel(0, StylesModel::ParagraphStyle))
m_stylesModel(new StylesModel(0, StylesModel::ParagraphStyle)),
m_mapper(new QSignalMapper(this))
{
widget.setupUi(this);
widget.alignCenter->setDefaultAction(tool->action("format_aligncenter"));
......@@ -83,15 +89,12 @@ SimpleParagraphWidget::SimpleParagraphWidget(TextTool *tool, QWidget *parent)
connect(widget.increaseIndent, SIGNAL(clicked(bool)), this, SIGNAL(doneWithFocus()));
widget.bulletListButton->setDefaultAction(tool->action("format_bulletlist"));
widget.numberedListButton->setDefaultAction(tool->action("format_numberlist"));
widget.bulletListButton->setNumColumns(3);
widget.numberedListButton->setNumColumns(3);
fillListButtons();
widget.bulletListButton->addSeparator();
connect(widget.bulletListButton, SIGNAL(itemTriggered(int)), this, SLOT(listStyleChanged(int)));
connect(widget.numberedListButton, SIGNAL(itemTriggered(int)), this, SLOT(listStyleChanged(int)));
m_stylesModel->setStyleThumbnailer(m_thumbnailer);
widget.paragraphStyleCombo->setStylesModel(m_stylesModel);
......@@ -99,6 +102,8 @@ SimpleParagraphWidget::SimpleParagraphWidget(TextTool *tool, QWidget *parent)
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)), this, SLOT(slotShowStyleManager(int)));
connect(m_mapper, SIGNAL(mapped(int)), this, SLOT(changeListLevel(int)));
}
SimpleParagraphWidget::~SimpleParagraphWidget()
......@@ -151,13 +156,31 @@ void SimpleParagraphWidget::fillListButtons()
KoShapePaintingContext paintContext; //FIXME
textShape.paintComponent(p, zoomHandler, paintContext);
if(KoListStyle::isNumberingStyle(item.style)) {
widget.numberedListButton->addItem(pm, static_cast<int> (item.style));
} else {
widget.bulletListButton->addItem(pm, static_cast<int> (item.style));
}
widget.bulletListButton->addItem(pm, static_cast<int> (item.style));
}
}
widget.bulletListButton->addSeparator();
KAction *action = new KAction(i18n("Change List Level"),this);
//TODO: Uncomment the below line when the string freeze is over
//action->setToolTip(i18n("Change the level the list is at"));
QMenu *listLevelMenu = new QMenu();
const int levelIndent = 13;
for (int level = 0; level < 10; ++level) {
QWidgetAction *wa = new QWidgetAction(listLevelMenu);
ListLevelChooser *chooserWidget = new ListLevelChooser((levelIndent * level) + 5);
wa->setDefaultWidget(chooserWidget);
listLevelMenu->addAction(wa);
m_mapper->setMapping(wa,level + 1);
connect(chooserWidget, SIGNAL(clicked()), wa, SLOT(trigger()));
connect(wa, SIGNAL(triggered()), m_mapper, SLOT(map()));
}
action->setMenu(listLevelMenu);
widget.bulletListButton->addAction(action);
}
void SimpleParagraphWidget::setCurrentBlock(const QTextBlock &block)
......@@ -292,4 +315,12 @@ void SimpleParagraphWidget::slotShowStyleManager(int index)
emit doneWithFocus();
}
void SimpleParagraphWidget::changeListLevel(int level)
{
emit doneWithFocus();
if (m_blockSignals) return;
m_tool->setListLevel(level);
}
#include <SimpleParagraphWidget.moc>
......@@ -35,6 +35,8 @@ class KoStyleThumbnailer;
class StylesModel;
class StylesDelegate;
class QSignalMapper;
class SimpleParagraphWidget : public QWidget
{
Q_OBJECT
......@@ -57,6 +59,7 @@ signals:
private slots:
void listStyleChanged(int id);
void styleSelected(int index);
void changeListLevel(int level);
private:
enum DirectionButtonState {
......@@ -78,6 +81,7 @@ private:
TextTool *m_tool;
DirectionButtonState m_directionButtonState;
KoStyleThumbnailer *m_thumbnailer;
QSignalMapper *m_mapper;
StylesModel *m_stylesModel;
StylesDelegate *m_stylesDelegate;
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>230</width>
<width>232</width>
<height>90</height>
</rect>
</property>
......@@ -34,67 +34,67 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<zorder></zorder>
</widget>
</item>
<item row="0" column="0">
<layout class="QGridLayout" name="gridLayout">
<layout class="QGridLayout" name="gridLayout" columnstretch="0,2,0,0,0,0,0,0,0,0,0,0">
<property name="spacing">
<number>2</number>
</property>
<item row="2" column="0" colspan="2">
<widget class="FormattingButton" name="bulletListButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="2" colspan="2">
<widget class="FormattingButton" name="numberedListButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="2" column="4" colspan="2">
<widget class="QToolButton" name="decreaseIndent">
<item row="3" column="0">
<widget class="QToolButton" name="alignLeft">
<property name="autoRaise">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="6" colspan="2">
<widget class="QToolButton" name="increaseIndent">
<item row="3" column="5" colspan="2">
<widget class="QToolButton" name="alignBlock">
<property name="autoRaise">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="8">
<widget class="QToolButton" name="changeTextDirection"/>
<item row="1" column="0" colspan="12">
<widget class="StylesCombo" name="paragraphStyleCombo"/>
</item>
<item row="3" column="0">
<widget class="QToolButton" name="alignLeft">
<item row="2" column="10">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>100</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="3" colspan="2">
<widget class="QToolButton" name="alignRight">
<property name="autoRaise">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="1" colspan="2">
<widget class="QToolButton" name="alignCenter">
<item row="2" column="3">
<widget class="QToolButton" name="decreaseIndent">
<property name="autoRaise">
<bool>false</bool>
</property>
</widget>
</item>
<item row="3" column="3" colspan="2">
<widget class="QToolButton" name="alignRight">
<property name="autoRaise">
<bool>false</bool>
<item row="2" column="0" colspan="2">
<widget class="FormattingButton" name="bulletListButton">
<property name="text">
<string>...</string>
</property>
</widget>
</item>
<item row="3" column="5" colspan="2">
<widget class="QToolButton" name="alignBlock">
<item row="3" column="1" colspan="2">
<widget class="QToolButton" name="alignCenter">
<property name="autoRaise">
<bool>false</bool>
</property>
......@@ -116,22 +116,6 @@
</property>
</spacer>
</item>
<item row="1" column="0" colspan="12">
<widget class="StylesCombo" name="paragraphStyleCombo"/>
</item>
<item row="2" column="10">
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="3" column="11">
<widget class="QToolButton" name="moreOptions">
<property name="text">
......@@ -139,6 +123,16 @@
</property>
</widget>
</item>
<item row="2" column="5">
<widget class="QToolButton" name="increaseIndent">
<property name="autoRaise">
<bool>false</bool>
</property>
</widget>
</item>
<item row="2" column="7">
<widget class="QToolButton" name="changeTextDirection"/>
</item>
</layout>
</item>
</layout>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment