diff --git a/libs/CMakeLists.txt b/libs/CMakeLists.txt index 531873f7e8f..110c3ebe148 100644 --- a/libs/CMakeLists.txt +++ b/libs/CMakeLists.txt @@ -1,31 +1,32 @@ add_subdirectory( koplugin ) +add_subdirectory( widgetutils ) add_subdirectory( widgets ) add_subdirectory( odf ) add_subdirectory( textlayout ) add_subdirectory( kotext ) add_subdirectory( flake ) add_subdirectory( pigment ) add_subdirectory( main ) add_subdirectory( kundo2 ) add_subdirectory( vectorimage ) if (SHOULD_BUILD_SCRIPTING AND NOT CREATIVEONLY) add_subdirectory( kokross ) endif (SHOULD_BUILD_SCRIPTING AND NOT CREATIVEONLY) if (NOT CREATIVEONLY) add_subdirectory( kopageapp ) endif (NOT CREATIVEONLY) if(NOT TINY OR NOT CREATIVEONLY) add_subdirectory( koproperty ) # TODO move to independent place like kdesupport endif(NOT TINY OR NOT CREATIVEONLY) if (SHOULD_BUILD_CALLIGRADB) add_subdirectory( db ) # used by Kexi and Word's Biblio; TODO: remove when Predicate lib arrives endif (SHOULD_BUILD_CALLIGRADB) # only build koreport if possible if (SHOULD_BUILD_KOREPORT) add_subdirectory( koreport ) endif (SHOULD_BUILD_KOREPORT) diff --git a/libs/widgetutils/CMakeLists.txt b/libs/widgetutils/CMakeLists.txt new file mode 100644 index 00000000000..cdf5599d43b --- /dev/null +++ b/libs/widgetutils/CMakeLists.txt @@ -0,0 +1,24 @@ +include_directories(${KDE4_INCLUDES}) + +set(kowidgetutils_LIB_SRCS + KoGroupButton.cpp +) + +kde4_add_library(kowidgetutils SHARED ${kowidgetutils_LIB_SRCS}) + +target_link_libraries(kowidgetutils ${KDE4_KDEUI_LIBS}) +target_link_libraries(kowidgetutils LINK_INTERFACE_LIBRARIES ${KDE4_KDEUI_LIBS}) + +set_target_properties(kowidgetutils + PROPERTIES VERSION ${GENERIC_CALLIGRA_LIB_VERSION} SOVERSION ${GENERIC_CALLIGRA_LIB_SOVERSION} +) + +install(TARGETS kowidgetutils ${INSTALL_TARGETS_DEFAULT_ARGS}) + +install(FILES + kowidgetutils_export.h + KoGroupButton.h + + DESTINATION ${INCLUDE_INSTALL_DIR} + COMPONENT Devel +) diff --git a/libs/widgetutils/KoGroupButton.cpp b/libs/widgetutils/KoGroupButton.cpp new file mode 100644 index 00000000000..5df9dfb551c --- /dev/null +++ b/libs/widgetutils/KoGroupButton.cpp @@ -0,0 +1,126 @@ +/* This file is part of the KDE libraries + Copyright (C) 2007 Aurélien Gâteau + Copyright (C) 2012 Jean-Nicolas Artaud + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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 "KoGroupButton.h" + +// Qt +#include +#include +#include +#include + +// KDE +#include + +class KoGroupButton::Private +{ +public: + Private(const GroupPosition position) : groupPosition(position) + {} + GroupPosition groupPosition; + QWidget* dialogParent; +}; + +KoGroupButton::KoGroupButton(GroupPosition position, QWidget* parent) +: d(new Private(position)) +{ + d->dialogParent = parent; + + setToolButtonStyle(Qt::ToolButtonIconOnly); + setFocusPolicy(Qt::NoFocus); + setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Minimum); +} + +KoGroupButton::~KoGroupButton() +{ + delete d; +} + +void KoGroupButton::setGroupPosition(KoGroupButton::GroupPosition groupPosition) +{ + d->groupPosition = groupPosition; +} + +KoGroupButton::GroupPosition KoGroupButton::groupPosition() const +{ + return d->groupPosition; +} + +void KoGroupButton::paintEvent(QPaintEvent* event) +{ + if (groupPosition() == NoGroup) { + QToolButton::paintEvent(event); + return; + } + QStylePainter painter(this); + QStyleOptionToolButton opt; + initStyleOption(&opt); + QStyleOptionToolButton panelOpt = opt; + + // Panel + QRect& panelRect = panelOpt.rect; + switch (groupPosition()) { + case GroupLeft: + panelRect.setWidth(panelRect.width() * 2); + break; + case GroupCenter: + panelRect.setLeft(panelRect.left() - panelRect.width()); + panelRect.setWidth(panelRect.width() * 3); + break; + case GroupRight: + panelRect.setLeft(panelRect.left() - panelRect.width()); + break; + case NoGroup: + Q_ASSERT(0); + } + painter.drawPrimitive(QStyle::PE_PanelButtonTool, panelOpt); + + // Separator + const int y1 = opt.rect.top() + 6; + const int y2 = opt.rect.bottom() - 6; + if (d->groupPosition & GroupRight) { + const int x = opt.rect.left(); + painter.setPen(opt.palette.color(QPalette::Light)); + painter.drawLine(x, y1, x, y2); + } + if (d->groupPosition & GroupLeft) { + const int x = opt.rect.right(); + painter.setPen(opt.palette.color(QPalette::Mid)); + painter.drawLine(x, y1, x, y2); + } + + // Text + painter.drawControl(QStyle::CE_ToolButtonLabel, opt); + + // Filtering message on tooltip text for CJK to remove accelerators. + // Quoting ktoolbar.cpp: + // """ + // CJK languages use more verbose accelerator marker: they add a Latin + // letter in parenthesis, and put accelerator on that. Hence, the default + // removal of ampersand only may not be enough there, instead the whole + // parenthesis construct should be removed. Provide these filtering i18n + // messages so that translators can use Transcript for custom removal. + // """ + if (!actions().isEmpty()) { + QAction* action = actions().first(); + setToolTip(i18nc("@info:tooltip of custom triple button", "%1", action->toolTip())); + } +} + +#include diff --git a/libs/widgetutils/KoGroupButton.h b/libs/widgetutils/KoGroupButton.h new file mode 100644 index 00000000000..d5b9398e072 --- /dev/null +++ b/libs/widgetutils/KoGroupButton.h @@ -0,0 +1,60 @@ +/* This file is part of the KDE libraries + Copyright (C) 2007 Aurélien Gâteau + Copyright (C) 2012 Jean-Nicolas Artaud + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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 KOGROUPBUTTON_H +#define KOGROUPBUTTON_H + +#include "kowidgetutils_export.h" + +// Qt +#include + +/** + * A thin tool button which can be grouped with another and look like one solid + * bar: + * + * ( button1 | button2 ) + */ +class KOWIDGETUTILS_EXPORT KoGroupButton : public QToolButton +{ + Q_OBJECT + Q_ENUMS( GroupPosition ) + Q_PROPERTY( GroupPosition groupPosition READ groupPosition WRITE setGroupPosition ) +public: + enum GroupPosition { + NoGroup, + GroupLeft, + GroupRight, + GroupCenter + }; + + explicit KoGroupButton(GroupPosition position, QWidget* parent = 0); + virtual ~KoGroupButton(); + + void setGroupPosition(KoGroupButton::GroupPosition groupPosition); + KoGroupButton::GroupPosition groupPosition() const; + +protected: + virtual void paintEvent(QPaintEvent* event); + +private: + class Private; + Private *const d; +}; + +#endif /* KOGROUPBUTTON_H */ diff --git a/libs/widgetutils/README b/libs/widgetutils/README new file mode 100644 index 00000000000..13a177aed35 --- /dev/null +++ b/libs/widgetutils/README @@ -0,0 +1,2 @@ +kowidgetutils - this library contains utilities for Calligra. It has light dependencies compared +to kowidgets library; the only dependency is QtCore and QtGui (QWidgets). diff --git a/libs/widgetutils/kowidgetutils_export.h b/libs/widgetutils/kowidgetutils_export.h new file mode 100644 index 00000000000..950e95c59d9 --- /dev/null +++ b/libs/widgetutils/kowidgetutils_export.h @@ -0,0 +1,44 @@ +/* This file is part of the KDE project + Copyright (C) 2012 Jarosław Staniek + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + 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 KOWIDGETUTILS_EXPORT_H +#define KOWIDGETUTILS_EXPORT_H + +/* needed for KDE_EXPORT and KDE_IMPORT macros */ +#include + +/* We use _WIN32/_WIN64 instead of Q_OS_WIN so that this header can be used from C files too */ +#if defined _WIN32 || defined _WIN64 + +#ifndef KOWIDGETUTILS_EXPORT +# if defined(MAKE_KOWIDGETUTILS_LIB) +/* We are building this library */ +# define KOWIDGETUTILS_EXPORT KDE_EXPORT +# else +/* We are using this library */ +# define KOWIDGETUTILS_EXPORT KDE_IMPORT +# endif +#endif + +#else /* UNIX */ + +#define KOWIDGETUTILS_EXPORT KDE_EXPORT + +#endif + +#endif