Commit 876c11bc authored by Michael Zhou's avatar Michael Zhou

The internal color selector is partially moved to kritawidgets.

It is now splited into 2 classes: KisBasicInternalColorSelector in kritawidgets
and KisDlgInternalColorSelector in kritaui. The first one does not have
screen color picker, as KisScreenColorPicker depends on too many things in
kritaimage and kritaui.
parent f2b635c1
......@@ -234,7 +234,6 @@ set(kritaui_LIB_SRCS
widgets/kis_paintop_preset_icon_library.cpp
widgets/kis_pattern_chooser.cc
widgets/kis_popup_button.cc
widgets/kis_preset_chooser.cpp
widgets/kis_progress_widget.cpp
widgets/kis_selection_options.cc
......@@ -259,12 +258,6 @@ set(kritaui_LIB_SRCS
widgets/kis_screen_color_picker.cpp
widgets/kis_preset_live_preview_view.cpp
widgets/KoDualColorButton.cpp
widgets/kis_color_button.cpp
# widgets/KisVisualColorSelector.cpp
# widgets/KisVisualColorSelectorShape.cpp
# widgets/KisVisualEllipticalSelectorShape.cpp
# widgets/KisVisualRectangleSelectorShape.cpp
# widgets/KisVisualTriangleSelectorShape.cpp
widgets/KoStrokeConfigWidget.cpp
widgets/KoFillConfigWidget.cpp
......@@ -389,7 +382,7 @@ set(kritaui_LIB_SRCS
flake/KisReferenceImagesLayer.cpp
flake/KisReferenceImagesLayer.h
# kis_dlg_internal_color_selector.cpp
kis_dlg_internal_color_selector.cpp
)
if(WIN32)
......
#include <QHBoxLayout>
#include <QDebug>
#include "kis_dlg_internal_color_selector.h"
#include "kis_screen_color_picker.h"
KisDlgInternalColorSelector::KisDlgInternalColorSelector(QWidget* parent, KoColor color, Config config, const QString &caption, const KoColorDisplayRendererInterface *displayRenderer)
: KisBasicInternalColorSelector(parent, color, config, caption, displayRenderer)
{
m_screenColorPicker = new KisScreenColorPicker(this);
m_ui->screenColorPickerWidget->setLayout(new QHBoxLayout(m_ui->screenColorPickerWidget));
m_ui->screenColorPickerWidget->layout()->addWidget(m_screenColorPicker);
qDebug() << "dlg setup";
if (config.screenColorPicker) {
connect(m_screenColorPicker, SIGNAL(sigNewColorPicked(KoColor)),this, SLOT(slotColorUpdated(KoColor)));
qDebug() << "dlg setup connected";
} else {
m_ui->screenColorPickerWidget->hide();
}
}
void KisDlgInternalColorSelector::updateAllElements(QObject *source)
{
KisBasicInternalColorSelector::updateAllElements(source);
m_screenColorPicker->updateIcons();
}
KoColor KisDlgInternalColorSelector::getModalColorDialog(const KoColor color, QWidget* parent, QString caption)
{
Config config = Config();
KisDlgInternalColorSelector dialog(parent, color, config, caption);
dialog.setPreviousColor(color);
dialog.exec();
return dialog.getCurrentColor();
}
#ifndef KIS_DLG_INTERNAL_COLOR_SELECTOR_H
#define KIS_DLG_INTERNAL_COLOR_SELECTOR_H
#include "kritaui_export.h"
#include "KisBasicInternalColorSelector.h"
#include "kis_screen_color_picker.h"
/*
* A color selector with a screen color picker.
*
* KisScreenColorPicker needs lots of resources in the library kritaui and
* kritaimage, therefore, the color selector in kritawidgets (which is a
* dependency of kritaui), called KisBasicInternalColorSelector, cannot use the
* color picker.
*
* This class is a temporary solution. If classes used by the screen color
* picker can be moved to libraries that don't rely on kritawidgets (most of
* these classes don't rely on kritawidgets themselves), then the color picker
* related code can be moved into KisBasicInternalColorPicker, and we will have
* a complete internal color selector that can be used everywhere.
*/
class KRITAUI_EXPORT KisDlgInternalColorSelector : public KisBasicInternalColorSelector
{
Q_OBJECT
public:
KisDlgInternalColorSelector(QWidget* parent,
KoColor color,
Config config,
const QString &caption,
const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance());
void updateAllElements(QObject *source) override;
static KoColor getModalColorDialog(const KoColor color, QWidget* parent = Q_NULLPTR, QString caption = QString());
private:
KisScreenColorPicker *m_screenColorPicker;
};
#endif // KIS_DLG_INTERNAL_COLOR_SELECTOR_H
......@@ -69,7 +69,7 @@
#include "kis_favorite_resource_manager.h"
#include "kis_config.h"
#include "widgets/kis_popup_button.h"
#include "kis_popup_button.h"
#include "widgets/kis_iconwidget.h"
#include "widgets/kis_tool_options_popup.h"
#include "widgets/kis_paintop_presets_popup.h"
......
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>WdgDlgInternalColorSelector</class>
<widget class="QDialog" name="WdgDlgInternalColorSelector">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>505</width>
<height>483</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontal">
<item>
<layout class="QVBoxLayout" name="leftPane">
<item>
<widget class="KisVisualColorSelector" name="visualSelector" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>90</width>
<height>90</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="KisSpinboxColorSelector" name="spinboxselector" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>50</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::StyledPanel</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Sunken</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
<property name="midLineWidth">
<number>2</number>
</property>
<layout class="QHBoxLayout" name="nextprevlayout">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="KoColorPatch" name="currentColor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>70</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="KoColorPatch" name="previousColor" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>25</width>
<height>25</height>
</size>
</property>
</widget>
</item>
</layout>
</widget>
</item>
</layout>
</item>
<item>
<layout class="QVBoxLayout" name="rightPane">
<item>
<widget class="KisPaletteView" name="paletteBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Expanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>90</width>
<height>0</height>
</size>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="topMargin">
<number>0</number>
</property>
<item>
<widget class="KisPopupButton" name="paletteList">
<property name="sizePolicy">
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>0</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="SqueezedComboBox" name="cmbNameList">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="editable">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="KisScreenColorPicker" name="screenColorPicker" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>50</width>
<height>50</height>
</size>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>KisPopupButton</class>
<extends>QPushButton</extends>
<header>kis_popup_button.h</header>
</customwidget>
<customwidget>
<class>KisPaletteView</class>
<extends>QTableView</extends>
<header location="global">kis_palette_view.h</header>
</customwidget>
<customwidget>
<class>SqueezedComboBox</class>
<extends>QComboBox</extends>
<header location="global">squeezedcombobox.h</header>
</customwidget>
<customwidget>
<class>KisSpinboxColorSelector</class>
<extends>QWidget</extends>
<header>kis_spinbox_color_selector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisScreenColorPicker</class>
<extends>QWidget</extends>
<header>kis_screen_color_picker.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KisVisualColorSelector</class>
<extends>QWidget</extends>
<header>KisVisualColorSelector.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>KoColorPatch</class>
<extends>QWidget</extends>
<header>KoColorPatch.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>WdgDlgInternalColorSelector</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>WdgDlgInternalColorSelector</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
......@@ -20,7 +20,7 @@
#ifndef KIS_ICONWIDGET_H_
#define KIS_ICONWIDGET_H_
#include <widgets/kis_popup_button.h>
#include <kis_popup_button.h>
class KoResource;
class KoAbstractResourceServerAdapter;
......
......@@ -32,6 +32,7 @@
#include <QShowEvent>
#include <QFontDatabase>
#include <QWidgetAction>
#include <QDesktopWidget>
#include <kconfig.h>
#include <klocalizedstring.h>
......@@ -61,6 +62,7 @@
#include <brushengine/kis_paintop_factory.h>
#include <kis_preset_live_preview_view.h>
class KisPopupButton;
struct KisPaintOpPresetsPopup::Private
{
......@@ -73,6 +75,7 @@ public:
QFont smallFont;
KisCanvasResourceProvider *resourceProvider;
KisFavoriteResourceManager *favoriteResManager;
KisPopupButton *popupButton; // button that invokes this popup
bool detached;
bool ignoreHideEvents;
......@@ -673,7 +676,10 @@ void KisPaintOpPresetsPopup::showEvent(QShowEvent *)
void KisPaintOpPresetsPopup::resizeEvent(QResizeEvent* event)
{
QWidget::resizeEvent(event);
emit sizeChanged();
// Make sure resizing doesn't push this widget out of the screen
QRect screenRect = QApplication::desktop()->availableGeometry(this);
QRect newPositionRect = kisEnsureInRect(this->rect(), screenRect);
this->parentWidget()->setGeometry(newPositionRect);
}
bool KisPaintOpPresetsPopup::detached() const
......
......@@ -112,7 +112,6 @@ Q_SIGNALS:
void dirtyPresetToggled(bool value);
void eraserBrushSizeToggled(bool value);
void eraserBrushOpacityToggled(bool value);
void sizeChanged();
void brushEditorShown();
void createPresetFromScratch(const QString& paintOpName);
......
......@@ -27,11 +27,13 @@
#include <QWindow>
#include <QTimer>
// #include "KisMainWindow.h"
#include <kis_canvas2.h>
#include "kis_shared_ptr.h"
#include "kis_icon.h"
#include "kis_screen_color_picker.h"
// #include "KisMainWindow.h"
#include "kis_image.h"
#include <kis_canvas2.h>
#include "kis_wrapped_rect.h"
#include "KisPart.h"
......
......@@ -57,7 +57,7 @@ public Q_SLOTS:
private Q_SLOTS:
void updateColorPicking();
protected:
void changeEvent(QEvent *event) override;
void changeEvent(QEvent *event);
private:
struct Private; //The private struct
const QScopedPointer<Private> m_d; //the private pointer
......
......@@ -94,7 +94,7 @@ set(kritawidgets_LIB_SRCS
kis_spinbox_color_selector.cpp
kis_dlg_internal_color_selector.cpp
KisBasicInternalColorSelector.cpp
KisPaletteChooser.cpp
KisVisualColorSelector.cpp
......@@ -102,6 +102,8 @@ set(kritawidgets_LIB_SRCS
KisVisualEllipticalSelectorShape.cpp
KisVisualRectangleSelectorShape.cpp
KisVisualTriangleSelectorShape.cpp
kis_popup_button.cc
kis_color_button.cpp
)
ki18n_wrap_ui( kritawidgets_LIB_SRCS
......@@ -113,11 +115,25 @@ ki18n_wrap_ui( kritawidgets_LIB_SRCS
KoPageLayoutWidget.ui
KoShadowConfigWidget.ui
WdgPaletteChooser.ui
WdgBasicInternalColorSelector.ui
)
add_library(kritawidgets SHARED ${kritawidgets_LIB_SRCS})
generate_export_header(kritawidgets BASE_NAME kritawidgets)
target_link_libraries(kritawidgets kritaodf kritaglobal kritaflake kritapigment kritawidgetutils Qt5::PrintSupport KF5::CoreAddons KF5::ConfigGui KF5::GuiAddons KF5::WidgetsAddons KF5::ConfigCore KF5::Completion)
target_link_libraries(kritawidgets
kritaodf
kritaglobal
kritaflake
kritapigment
kritawidgetutils
Qt5::PrintSupport
KF5::CoreAddons
KF5::ConfigGui
KF5::GuiAddons
KF5::WidgetsAddons
KF5::ConfigCore
KF5::Completion
)
if(X11_FOUND)
target_link_libraries(kritawidgets Qt5::X11Extras ${X11_LIBRARIES})
......
......@@ -33,7 +33,7 @@
#include <QStyleOptionButton>
#include <KoColor.h>
#include <kis_dlg_internal_color_selector.h>
#include <KisBasicInternalColorSelector.h>
class KisColorButton::KisColorButtonPrivate
{
......@@ -52,7 +52,7 @@ public:
KoColor col;
QPoint mPos;
#ifndef Q_OS_OSX
QPointer<KisDlgInternalColorSelector> dialogPtr;
QPointer<KisBasicInternalColorSelector> dialogPtr;
#else
QPointer<QColorDialog> dialogPtr;
#endif
......@@ -322,7 +322,7 @@ void KisColorButton::mouseMoveEvent(QMouseEvent *e)
void KisColorButton::KisColorButtonPrivate::_k_chooseColor()
{
#ifndef Q_OS_OSX
KisDlgInternalColorSelector *dialog = dialogPtr.data();
KisBasicInternalColorSelector *dialog = dialogPtr.data();
#else
QColorDialog *dialog = dialogPtr.data();
#endif
......@@ -338,10 +338,10 @@ void KisColorButton::KisColorButtonPrivate::_k_chooseColor()
return;
}
KisDlgInternalColorSelector::Config cfg;
KisBasicInternalColorSelector::Config cfg;
cfg.paletteBox = q->paletteViewEnabled();
#ifndef Q_OS_OSX
dialog = new KisDlgInternalColorSelector(q,
dialog = new KisBasicInternalColorSelector(q,
q->color(),
cfg,
i18n("Choose a color"));
......@@ -363,7 +363,7 @@ void KisColorButton::KisColorButtonPrivate::_k_chooseColor()
void KisColorButton::KisColorButtonPrivate::_k_colorChosen()
{
#ifndef Q_OS_OSX
KisDlgInternalColorSelector *dialog = dialogPtr.data();
KisBasicInternalColorSelector *dialog = dialogPtr.data();
#else
QColorDialog *dialog = dialogPtr.data();
#endif
......
......@@ -21,7 +21,7 @@
#ifndef KisColorButton_H
#define KisColorButton_H
#include <kritaui_export.h>
#include <kritawidgets_export.h>
#include <KoColor.h>
#include <QPushButton>
......@@ -36,7 +36,7 @@ class KisColorButtonPrivate;
*
* \image html KisColorButton.png "KDE Color Button"
*/
class KRITAUI_EXPORT KisColorButton : public QPushButton
class KRITAWIDGETS_EXPORT KisColorButton : public QPushButton
{
Q_OBJECT
......
This diff is collapsed.
/*
* Copyright (C) Wolthera van Hovell tot Westerflier <griffinvalley@gmail.com>, (C) 2016
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISINTERNALCOLORSELECTOR_H
#define KISINTERNALCOLORSELECTOR_H
#include "kritawidgets_export.h"
#include "KoColor.h"
#include "KoColorSpace.h"
#include "KoColorDisplayRendererInterface.h"
#include "KoColorSet.h"
#include <QScopedPointer>
#include "ui_wdgdlginternalcolorselector.h"
/**
* @brief The KisInternalColorSelector class
*
* A non-modal color selector dialog that is not a plugin and can thus be used for filters.
*/
class KRITAWIDGETS_EXPORT KisDlgInternalColorSelector : public QDialog
{
Q_OBJECT
public:
struct Config
{
Config() :
modal(true),
visualColorSelector(true),
paletteBox(true),
screenColorPicker(true),
prevNextButtons(true),
hexInput(true),
useAlpha(false){}
bool modal;
bool visualColorSelector;
bool paletteBox;
bool screenColorPicker;
bool prevNextButtons;
bool hexInput;
bool useAlpha;
};
KisDlgInternalColorSelector(QWidget* parent, KoColor color, Config config, const QString &caption, const KoColorDisplayRendererInterface *displayRenderer = KoDumbColorDisplayRenderer::instance());
~KisDlgInternalColorSelector() override;
/**
* @brief slotColorSpaceChanged
* Color space has changed, use this dialog to change the colorspace.
*/
void colorSpaceChanged(const KoColorSpace *cs);
/**
* @brief lockUsedColorSpace
* Lock the used colorspace of this selector.
* @param cs
*/
void lockUsedColorSpace(const KoColorSpace *cs);
/**
* @brief setDisplayRenderer
* Set the display renderer. This is necessary for HDR color manage support.
* @param displayRenderer
*/
void setDisplayRenderer(const KoColorDisplayRendererInterface *displayRenderer);
/**
* @brief getModalColorDialog
* Execute this dialog modally. The function returns
* the KoColor you want.
* @param color - The current color. Make sure this is in the color space you want your
* end color to be in.
* @param chooseAlpha - Whether or not the alpha-choosing functionality should be used.
*/
static KoColor getModalColorDialog(const KoColor color, QWidget* parent = Q_NULLPTR, QString caption = QString());
/**
* @brief getColor
* Wrapper function that enables makes this class interchangable with QColorDialog sometimes.
*/
static KoColor getColor(const KoColor color, QWidget* parent = Q_NULLPTR, QString caption = QString())
{
return getModalColorDialog(color, parent, caption);
}
/**
* @brief getCurrentColor
* @return gives currently active color;
*/
KoColor getCurrentColor();
void chooseAlpha(bool chooseAlpha);
Q_SIGNALS:
/**
* @brief signalForegroundColorChosen
* The most important signal. This will sent out when a color has been picked from the selector.
* There will be a small delay to make sure that the selector causes too many updates.
*
* Do not connect this to slotColorUpdated.
* @param color The new color chosen
*/
void signalForegroundColorChosen(KoColor color);
public Q_SLOTS:
/**
* @brief slotColorUpdated
* Very important slot. Is connected to krita's resources to make sure it has
* the currently active color. It's very important that this function is able to understand
* when the signal came from itself.
* @param newColor This is the new color.
*/
void slotColorUpdated(KoColor newColor);
/**
* @brief slotSetColorFromPatch
* update current color from kocolorpatch.
* @param patch
*/
void slotSetColorFromPatch(KoColorPatch* patch);
/**
* @brief setPreviousColor
* set the previous color.
*/
void setPreviousColor(KoColor c);
<