Commit 02896b65 authored by C. Boemann's avatar C. Boemann

This patch makes a huge change as to when config ui are in a docker and when it is

in a tool.

This new way of working was discussed with several people. The config
widgets were part of the 8 hour akademy 2012 Calligra UI brainstorming. This commit
implements what was designed.

The needed config widgets when working with a particular tool are now made available as
tool option widgets, so the user now directly has what is needed and nothing more.

The following config widgets are new but in large part reimplement what was already there:
 o Stroke config widget,
 o Fill config widget,
 o Shadow config widget,
 o Opacity config widget.

The snap guide config widget has gone the opposite way and is now a docker.

This patch was co-written with: Jean-Nicolas Artaud <jeannicolasartaud@gmail.com>
A big thank you, and also to Thomas Pfeiffer and Arjen Hiemstra for the ui discussions,
as well as numerous other people

REVIEW: 108569
parent 12781bc0
......@@ -79,10 +79,11 @@ set(KRITA_INCLUDES
${KOMAIN_INCLUDES}
${BASICFLAKES_INCLUDES}
${CMAKE_SOURCE_DIR}/libs/widgets/resources
${CMAKE_SOURCE_DIR}/libs/widgets/colorwidgets
${CMAKE_SOURCE_DIR}/libs/widgetutils
${EIGEN2_INCLUDE_DIR}
# 'Export' this for use by filters
CACHE INTERNAL ""
)
......
add_subdirectory(plugin)
include_directories(${KOTEXT_INCLUDES} ${KOODF_INCLUDES} ${PIGMENT_INCLUDES} ${KOWIDGETS_INCLUDES})
include_directories(${KOTEXT_INCLUDES} ${KOODF_INCLUDES} ${PIGMENT_INCLUDES} ${KOMAIN_INCLUDES})
set(basicflakes_LIB_SRCS
tools/KoCreatePathTool.cpp
......
......@@ -30,6 +30,7 @@
#include "KoCanvasResourceManager.h"
#include "KoDocumentResourceManager.h"
#include "KoShapePaintingContext.h"
#include "KoStrokeConfigWidget.h"
#include <KNumInput>
#include <KLocale>
......@@ -386,6 +387,12 @@ QList<QWidget *> KoCreatePathTool::createOptionWidgets()
angleWidget->setWindowTitle(i18n("Angle Constraints"));
list.append(angleWidget);
KoStrokeConfigWidget *strokeWidget = new KoStrokeConfigWidget(0);
strokeWidget->setWindowTitle(i18n("Line"));
strokeWidget->setCanvas(canvas());
list.append(strokeWidget);
connect(angleEdit, SIGNAL(valueChanged(int)), this, SLOT(angleDeltaChanged(int)));
return list;
......
......@@ -34,6 +34,7 @@
#include <KoPathPointData.h>
#include <KoPathPointMergeCommand.h>
#include <KoShapePaintingContext.h>
#include <KoStrokeConfigWidget.h>
#include <knuminput.h>
#include <klocale.h>
......@@ -272,8 +273,9 @@ void KoPencilTool::finish(bool closePath)
addPathShape(path, closePath);
}
QWidget * KoPencilTool::createOptionWidget()
QList<QWidget *> KoPencilTool::createOptionWidgets()
{
QList<QWidget *> widgets;
QWidget *optionWidget = new QWidget();
QVBoxLayout * layout = new QVBoxLayout(optionWidget);
......@@ -328,8 +330,15 @@ QWidget * KoPencilTool::createOptionWidget()
modeBox->setCurrentIndex(m_mode);
stackedWidget->setCurrentIndex(m_mode);
return optionWidget;
optionWidget->setObjectName(i18n("Pencil"));
optionWidget->setWindowTitle(i18n("Pencil"));
widgets.append(optionWidget);
KoStrokeConfigWidget *strokeWidget = new KoStrokeConfigWidget(0);
strokeWidget->setWindowTitle(i18n("Line"));
strokeWidget->setCanvas(canvas());
widgets.append(strokeWidget);
return widgets;
}
void KoPencilTool::addPathShape(KoPathShape* path, bool closePath)
......
......@@ -48,7 +48,7 @@ public:
void deactivate();
protected:
virtual QWidget * createOptionWidget();
virtual QList<QWidget *> createOptionWidgets();
/**
* Add path shape to document.
......
......@@ -197,13 +197,9 @@ QList<QWidget *> KoPathTool::createOptionWidgets()
PathToolOptionWidget * toolOptions = new PathToolOptionWidget(this);
connect(this, SIGNAL(typeChanged(int)), toolOptions, SLOT(setSelectionType(int)));
//connect(this, SIGNAL(pathChanged(KoPathShape*)), widget, SLOT(setSelectedPath(KoPathShape*)));
updateOptionsWidget();
toolOptions->setWindowTitle(i18n("Line/Curve"));
list.append(toolOptions);
QWidget* widget = d->canvas->createSnapGuideConfigWidget();
widget->setWindowTitle(i18n("Snapping"));
list.append(widget);
return list;
}
......
......@@ -331,10 +331,6 @@ void KoModeBox::setOptionWidgets(const QList<QWidget *> &optionWidgetList)
layout->setVerticalSpacing(2);
int specialCount = 0;
foreach(QWidget *widget, optionWidgetList) {
if (widget->objectName().isEmpty()) {
Q_ASSERT(!(widget->objectName().isEmpty()));
continue; // skip this docker in release build when assert don't crash
}
if (!widget->windowTitle().isEmpty()) {
QLabel *l;
layout->addWidget(l = new QLabel(widget->windowTitle()), cnt++, 1, 1, 3, Qt::AlignHCenter);
......
......@@ -25,4 +25,4 @@ KoTextLayoutRootAreaProvider::KoTextLayoutRootAreaProvider()
KoTextLayoutRootAreaProvider::~KoTextLayoutRootAreaProvider()
{
}
\ No newline at end of file
}
......@@ -2,6 +2,7 @@ add_subdirectory( tests )
add_subdirectory( pics )
include_directories(${KOTEXT_INCLUDES} ${KOODF_INCLUDES} ${PIGMENT_INCLUDES})
include_directories(${CMAKE_SOURCE_DIR}/libs/widgetutils)
if (LIBATTICA_FOUND)
include_directories(${LIBATTICA_INCLUDE_DIR})
endif (LIBATTICA_FOUND)
......@@ -20,6 +21,7 @@ set(kowidgets_LIB_SRCS
KoPagePreviewWidget.cpp
KoPositionSelector.cpp
KoSliderCombo.cpp
KoColorPopupButton.cpp
KoUnitDoubleSpinBox.cpp
KoZoomAction.cpp
KoZoomController.cpp
......@@ -38,7 +40,10 @@ set(kowidgets_LIB_SRCS
KoUniColorChooser.cpp
KoUniColorDialog.cpp
KoXYColorSelector.cpp
KoResourcePopupAction.cpp
KoStrokeConfigWidget.cpp
KoFillConfigWidget.cpp
KoOpacityConfigWidget.cpp
KoShadowConfigWidget.cpp
KoIconToolTip.cpp
KoResourceItemChooser.cpp
......@@ -73,17 +78,17 @@ kde4_add_ui_files( kowidgets_LIB_SRCS
kde4_add_library(kowidgets SHARED ${kowidgets_LIB_SRCS})
if(GHNS)
target_link_libraries(kowidgets kotext pigmentcms ${KDE4_KNEWSTUFF3_LIBS})
if(GHNS)
target_link_libraries(kowidgets kotext pigmentcms kowidgetutils ${KDE4_KNEWSTUFF3_LIBS})
else(GHNS)
target_link_libraries(kowidgets kotext pigmentcms )
target_link_libraries(kowidgets kotext pigmentcms kowidgetutils)
endif (GHNS)
if(NEPOMUK)
target_link_libraries(kowidgets kotext pigmentcms ${NEPOMUK_LIBRARIES} ${SOPRANO_LIBRARIES})
target_link_libraries(kowidgets kotext pigmentcms kowidgetutils ${NEPOMUK_LIBRARIES} ${SOPRANO_LIBRARIES})
endif(NEPOMUK)
target_link_libraries(kowidgets LINK_INTERFACE_LIBRARIES kotext pigmentcms ${KDE4_KDEUI_LIBS})
target_link_libraries(kowidgets LINK_INTERFACE_LIBRARIES kotext pigmentcms kowidgetutils ${KDE4_KDEUI_LIBS})
set_target_properties(kowidgets PROPERTIES
VERSION ${GENERIC_CALLIGRA_LIB_VERSION} SOVERSION ${GENERIC_CALLIGRA_LIB_SOVERSION}
......@@ -107,6 +112,8 @@ install( FILES
KoColorPatch.h
KoStrokeConfigWidget.h
KoFillConfigWidget.h
KoOpacityConfigWidget.h
KoShadowConfigWidget.h
KoColorPopupAction.h
KoColorSetWidget.h
......
......@@ -33,6 +33,7 @@
#include <QMenu>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QToolButton>
#include <KColorDialog>
#include <KDebug>
......@@ -162,29 +163,39 @@ KoColor KoColorPopupAction::currentKoColor() const
void KoColorPopupAction::updateIcon( )
{
QSize iconSize(16,16);
QSize iconSize;
QToolButton *toolButton = dynamic_cast<QToolButton*>(parentWidget());
if (toolButton) {
iconSize = QSize(toolButton->iconSize());
} else {
iconSize = QSize(16, 16);
}
// This must be a QImage, as drawing to a QPixmap outside the
// UI thread will cause sporadic crashes.
QImage pm = icon().pixmap(iconSize).toImage();
if(pm.isNull())
{
pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied);
pm.fill(Qt::transparent);
// there was no icon set so we assume
// that we create an icon from the current color
QImage pm;
if (icon().isNull()) {
d->applyMode = false;
}
QPainter p(&pm);
if(d->applyMode) {
pm = icon().pixmap(iconSize).toImage();
if (pm.isNull()) {
pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied);
pm.fill(Qt::transparent);
}
QPainter p(&pm);
p.fillRect(0, iconSize.height() - 4, iconSize.width(), 4, d->currentColor.toQColor());
}
else {
p.end();
} else {
pm = QImage(iconSize, QImage::Format_ARGB32_Premultiplied);
pm.fill(Qt::transparent);
QPainter p(&pm);
d->checkerPainter.paint(p, QRect(QPoint(),iconSize));
p.fillRect(0, 0, iconSize.width(), iconSize.height(), d->currentColor.toQColor());
p.end();
}
p.end();
setIcon(QIcon(QPixmap::fromImage(pm)));
}
......
......@@ -52,16 +52,19 @@ public:
public slots:
/// Sets a new color to be displayed
void setCurrentColor( const QColor &color );
/// Sets a new color to be displayed
void setCurrentColor( const KoColor &color );
/// Returns the current color
QColor currentColor() const;
/// Returns the current color as a KoColor
KoColor currentKoColor() const;
/// update the icon - only needed if you resize the iconsize in the widget that shows the action
void updateIcon();
signals:
/**
* Emitted every time the color changes (by calling setColor() or
......@@ -77,7 +80,6 @@ private slots:
void opacityWasChanged( int opacity );
private:
void updateIcon();
class KoColorPopupActionPrivate;
KoColorPopupActionPrivate * const d;
};
......
/* This file is part of the KDE project
* Copyright (c) 2013 Jean-Nicolas Artaud <jeannicolasartaud@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 "KoColorPopupButton.h"
#include <QResizeEvent>
#include <QStyle>
#include <QStyleOptionToolButton>
#include "kdebug.h"
KoColorPopupButton::KoColorPopupButton(QWidget *parent)
: QToolButton(parent)
{
setToolButtonStyle(Qt::ToolButtonIconOnly);
}
KoColorPopupButton::~KoColorPopupButton()
{
}
QSize KoColorPopupButton::sizeHint() const
{
QStyleOptionToolButton opt;
initStyleOption(&opt);
return style()->sizeFromContents(QStyle::CT_ToolButton, &opt, QSize(16,16), this);
}
void KoColorPopupButton::resizeEvent(QResizeEvent *e)
{
QStyleOptionToolButton opt;
initStyleOption(&opt);
QSize size = iconSize();
QSize rect = style()->sizeFromContents(QStyle::CT_ToolButton, &opt, size, this);
int iconWidth = size.width() - rect.width() + e->size().width();
if (iconWidth != size.width()) {
size.setWidth(iconWidth);
setIconSize(size);
}
QToolButton::resizeEvent(e);
emit iconSizeChanged();
}
#include <KoColorPopupButton.moc>
/* This file is part of the KDE project
* Copyright (c) 2013 Jean-Nicolas Artaud <jeannicolasartaud@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 KOCOLORPOPUPBUTTON_H_
#define KOCOLORPOPUPBUTTON_H_
#include <QToolButton>
#include "kowidgets_export.h"
/**
* @short A widget for
*
*/
class KOWIDGETS_EXPORT KoColorPopupButton: public QToolButton
{
Q_OBJECT
public:
/**
* Constructor for the widget, where value is set to 0
*
* @param parent parent QWidget
*/
explicit KoColorPopupButton(QWidget *parent=0);
/**
* Destructor
*/
virtual ~KoColorPopupButton();
QSize sizeHint() const;
signals:
/// Emitted when a resource was selected
void iconSizeChanged();
protected:
virtual void resizeEvent(QResizeEvent *); ///< reimplemented from QToolButton
};
#endif
/* This file is part of the KDE project
* Made by Tomislav Lukman (tomislav.lukman@ck.tel.hr)
* Copyright (C) 2012 Jean-Nicolas Artaud <jeannicolasartaud@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 "KoFillConfigWidget.h"
#include <QToolButton>
#include <QHBoxLayout>
#include <QButtonGroup>
#include <QLabel>
#include <QSizePolicy>
#include <QBitmap>
#include <QAction>
#include <klocale.h>
#include <KoGroupButton.h>
#include <KoIcon.h>
#include <KoColor.h>
#include <KoColorPopupAction.h>
#include "KoResourceServerProvider.h"
#include "KoResourceServerAdapter.h"
#include "KoResourceSelector.h"
#include <KoCanvasController.h>
#include <KoSelection.h>
#include <KoToolManager.h>
#include <KoCanvasBase.h>
#include <KoCanvasController.h>
#include <KoCanvasResourceManager.h>
#include <KoDocumentResourceManager.h>
#include <KoShape.h>
#include <KoShapeManager.h>
#include <KoShapeController.h>
#include <KoShapeBackground.h>
#include <KoShapeBackgroundCommand.h>
#include <KoColorBackground.h>
#include <KoGradientBackground.h>
#include <KoPatternBackground.h>
#include <KoImageCollection.h>
#include <KoResourcePopupAction.h>
#include "KoZoomHandler.h"
#include "KoColorPopupButton.h"
static const char* const buttonnone[]={
"16 16 3 1",
"# c #000000",
"e c #ff0000",
"- c #ffffff",
"################",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"#--------------#",
"################"};
static const char* const buttonsolid[]={
"16 16 2 1",
"# c #000000",
". c #969696",
"################",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"#..............#",
"################"};
// FIXME: Smoother gradient button.
static const char* const buttongradient[]={
"16 16 15 1",
"# c #000000",
"n c #101010",
"m c #202020",
"l c #303030",
"k c #404040",
"j c #505050",
"i c #606060",
"h c #707070",
"g c #808080",
"f c #909090",
"e c #a0a0a0",
"d c #b0b0b0",
"c c #c0c0c0",
"b c #d0d0d0",
"a c #e0e0e0",
"################",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"#abcdefghijklmn#",
"################"};
static const char* const buttonpattern[]={
"16 16 4 1",
". c #0a0a0a",
"# c #333333",
"a c #a0a0a0",
"b c #ffffffff",
"################",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"#bbbbbaaaabbbbb#",
"#bbbbbaaaabbbbb#",
"#bbbbbaaaabbbbb#",
"#bbbbbaaaabbbbb#",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"#aaaaabbbbaaaaa#",
"################"};
class KoFillConfigWidget::Private
{
public:
Private()
: canvas(0)
{
}
KoColorPopupButton *colorButton;
QAction *noFillAction;
KoColorPopupAction *colorAction;
KoResourcePopupAction *gradientAction;
KoResourcePopupAction *patternAction;
QButtonGroup *group;
QWidget *spacer;
KoCanvasBase *canvas;
};
KoFillConfigWidget::KoFillConfigWidget(QWidget *parent)
: QWidget(parent)
, d(new Private())
{
setObjectName("Fill widget");
QHBoxLayout *layout = new QHBoxLayout(this);
layout->setMargin(0);
layout->setSpacing(0);
d->group = new QButtonGroup(this);
d->group->setExclusive(true);
// The button for no fill
KoGroupButton *button = new KoGroupButton(KoGroupButton::GroupLeft, this);
QPixmap noFillButtonIcon((const char **) buttonnone);
noFillButtonIcon.setMask(QBitmap(noFillButtonIcon));
button->setIcon(noFillButtonIcon);
button->setToolTip(i18nc("No stroke or fill", "None"));
button->setCheckable(true);
d->group->addButton(button, None);
layout->addWidget(button);
// The button for solid fill
button = new KoGroupButton(KoGroupButton::GroupCenter, this);
button->setIcon(QPixmap((const char **) buttonsolid));
button->setToolTip(i18nc("Solid color stroke or fill", "Solid"));
button->setCheckable(true);
d->group->addButton(button, Solid);
layout->addWidget(button);
// The button for gradient fill
button = new KoGroupButton(KoGroupButton::GroupCenter, this);
button->setIcon(QPixmap((const char **) buttongradient));
button->setToolTip(i18n("Gradient"));
button->setCheckable(true);
d->group->addButton(button, Gradient);
layout->addWidget(button);
// The button for pattern fill
button = new KoGroupButton(KoGroupButton::GroupRight, this);
button->setIcon(QPixmap((const char **) buttonpattern));
button->setToolTip(i18n("Pattern"));
button->setCheckable(true);
button->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
d->group->addButton(button, Pattern);
layout->addWidget(button);
connect(d->group, SIGNAL(buttonClicked(int)), this, SLOT(styleButtonPressed(int)));
d->colorButton = new KoColorPopupButton(this);
d->colorButton->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
layout->addWidget(d->colorButton);
d->noFillAction = new QAction(0);