diff options
author | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
---|---|---|
committer | toma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2009-11-25 17:56:58 +0000 |
commit | 47d455dd55be855e4cc691c32f687f723d9247ee (patch) | |
tree | 52e236aaa2576bdb3840ebede26619692fed6d7d /kcoloredit | |
download | tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.tar.gz tdegraphics-47d455dd55be855e4cc691c32f687f723d9247ee.zip |
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdegraphics@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'kcoloredit')
45 files changed, 5023 insertions, 0 deletions
diff --git a/kcoloredit/Makefile.am b/kcoloredit/Makefile.am new file mode 100644 index 00000000..1f377635 --- /dev/null +++ b/kcoloredit/Makefile.am @@ -0,0 +1,35 @@ +INCLUDES = $(all_includes) + +kcoloredit_SOURCES = kzcolorselector.cpp imageselection.cpp \ + texteditselection.cpp gradientselection.cpp colorselector.cpp \ + kxycolorselector.cpp paletteview.cpp paletteviewscrolledarea.cpp \ + editablestreamhistory.cpp color.cpp palette.cpp loadpalettedlg.cpp \ + kcoloreditview.cpp kcoloreditdoc.cpp kcoloredit.cpp main.cpp +kcoloredit_METASOURCES = AUTO +kcoloredit_LDADD = $(LIB_KDEUI) $(LIB_KFILE) +kcoloredit_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +rcdir = $(kde_datadir)/kcoloredit +rc_DATA = kcoloreditui.rc + +bin_PROGRAMS = kcoloredit kcolorchooser +kcolorchooser_SOURCES = kcolorchooser.cpp +kcolorchooser_LDADD = $(LIB_KDEUI) +kcolorchooser_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +noinst_HEADERS = color.h colorselector.h editablestreamhistory.h \ + gradientselection.h imageselection.h kcoloredit.h kcoloreditdoc.h \ + kcoloreditview.h kxycolorselector.h kzcolorselector.h \ + loadpalettedlg.h main.h palette.h palettehistory.h paletteview.h \ + resource.h texteditselection.h + +xdg_apps_DATA = kcoloredit.desktop kcolorchooser.desktop + +KDE_ICON = kcoloredit kcolorchooser + +EXTRA_DIST = $(xdg_apps_DATA) + +messages: rc.cpp + $(EXTRACTRC) *.rc > rc.cpp + $(XGETTEXT) $(kcoloredit_SOURCES) rc.cpp resource.h -o $(podir)/kcoloredit.pot + diff --git a/kcoloredit/color.cpp b/kcoloredit/color.cpp new file mode 100644 index 00000000..db18a5a5 --- /dev/null +++ b/kcoloredit/color.cpp @@ -0,0 +1,78 @@ +/*************************************************************************** + color.cpp - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "color.h" + +Color::Color(){ + setComponents(0, 0, 0); + setName(""); +} +Color::Color(const int red, const int green, const int blue, const QString& name) { + setComponents(red, green, blue); + setName(name); +} +Color::~Color(){ +} + +void Color::setComponent(const int index, const int value) { + m_components[index] = value; +} + +void Color::setComponents(const int red, const int green, const int blue) { + setComponent(RED_INDEX, red); + setComponent(GREEN_INDEX, green); + setComponent(BLUE_INDEX, blue); +} + +void Color::setName(const QString& name) { + m_name = name; +} + +int Color::component(const int index) const { + return m_components[index]; +} + +const int* Color::components() const{ + return m_components; +} + +const QString& Color::name() const { + return m_name; +} + +bool Color::equals(const Color& color) { + return component(RED_INDEX) == color.component(RED_INDEX) && + component(GREEN_INDEX) == color.component(GREEN_INDEX) && + component(BLUE_INDEX) == color.component(BLUE_INDEX); +} + +void Color::modifyComponent(const int index, const int value, const double amount) { + int comp = component(index); + comp += (int)(value*amount + 0.5); + if(comp > RGB_MAX_COMPONENT_VALUE) + comp = RGB_MAX_COMPONENT_VALUE; + else if(comp < 0) + comp = 0; + setComponent(index, comp); +} + +void Color::modifyComponents(const int red, const int green, const int blue, const double amount) { + modifyComponent(RED_INDEX, red, amount); + modifyComponent(GREEN_INDEX, green, amount); + modifyComponent(BLUE_INDEX, blue, amount); +} + diff --git a/kcoloredit/color.h b/kcoloredit/color.h new file mode 100644 index 00000000..723ba2f0 --- /dev/null +++ b/kcoloredit/color.h @@ -0,0 +1,81 @@ +/*************************************************************************** + color.h - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef COLOR_H +#define COLOR_H + +#include "main.h" + +/**A color class, holds its components and name + *@author Artur Rataj + */ + +class Color { + public: + /** indices of components + */ + enum { RED_INDEX = 0, + GREEN_INDEX = 1, + BLUE_INDEX = 2, + COMPONENTS_NUM = 3 }; + + public: + /** constructs a color + */ + Color(); + /** constructs a color with given components and a name + */ + Color(const int red, const int green, const int blue, const QString& name); + ~Color(); + /** sets a component + */ + void setComponent(const int index, const int value); + /** sets components + */ + void setComponents(const int red, const int green, const int blue); + /** sets a name + */ + void setName(const QString& name); + /** @return a component + */ + int component(const int index) const; + /** @return components + */ + const int* components() const; + /** @return a color name + */ + const QString& name() const; + /** @return if is equal to color + */ + bool equals(const Color& color); + /** modifies a component, amount can be either positive or negative + */ + void modifyComponent(const int index, const int value, const double amount); + /** modifies components, amount can be either positive or negative + */ + void modifyComponents(const int red, const int green, const int blue, const double amount); + + protected: + /** components table + */ + int m_components[COMPONENTS_NUM]; + /** a color name + */ + QString m_name; +}; + +#endif diff --git a/kcoloredit/colorselector.cpp b/kcoloredit/colorselector.cpp new file mode 100644 index 00000000..2b0530d3 --- /dev/null +++ b/kcoloredit/colorselector.cpp @@ -0,0 +1,212 @@ +/*************************************************************************** + colorselector.cpp - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <math.h> + +#include <qlayout.h> +/* #include <qtabwidget.h> */ +#include <qradiobutton.h> +#include <qlabel.h> +#include <qslider.h> +#include <kseparator.h> +#include <klocale.h> + +#include "main.h" +#include "imageselection.h" +#include "texteditselection.h" +#include "colorselector.h" + +ColorSelector::ColorSelector(QWidget *parent, const char *name ) : QWidget(parent, name) { + fComponentsMode = false; + QVBoxLayout* topLayout = new QVBoxLayout(this, 4); + /* + QTabWidget* pages = new QTabWidget(this); + */ + gradientSelection = new GradientSelection(this); + connect(gradientSelection, SIGNAL( valueChanged(Color*) ), + SLOT( slotGradientSelectionChangeColor(Color*) )); + connect(gradientSelection, SIGNAL( synchronizeColor() ), + SLOT( slotGradientSelectionSynchronizeColor() )); + connect(this, SIGNAL( valueChanged(Color*) ), gradientSelection, SLOT( slotSetValue(Color*) )); + /* + pages->addTab(gradientSelection, i18n( "Gradient" )); + ImageSelection* imageSelection = new ImageSelection(this); + connect(imageSelection, SIGNAL( valueChanged(Color*) ), SLOT( slotSetColor(Color*) )); + connect(this, SIGNAL( valueChanged(Color*) ), imageSelection, SLOT( slotSetValue(Color*) )); + pages->addTab(imageSelection, i18n( "Image" )); + topLayout->addWidget(pages, 10); + */ + topLayout->addWidget(gradientSelection, 10); + KSeparator* hLine = new KSeparator(KSeparator::HLine, this); + topLayout->addWidget(hLine); + QHBoxLayout* layout = new QHBoxLayout(); + TextEditSelection* textEditSelection = new TextEditSelection(this); + connect(textEditSelection, SIGNAL( valueChanged(Color*) ), SLOT( slotSetColor(Color*) )); + connect(this, SIGNAL( valueChanged(Color*) ), textEditSelection, SLOT( slotSetValue(Color*) )); + QVBoxLayout* colorChangeLayout = new QVBoxLayout(); + colorChangeLayout->setMargin(2); + QRadioButton* replaceButton = new QRadioButton(i18n( "Replace" ), this); + connect(replaceButton, SIGNAL( clicked() ), SLOT( slotColorReplace() )); + replaceButton->setChecked(true); + colorChangeButtons.insert(replaceButton); + colorChangeLayout->addWidget(replaceButton); + QRadioButton* changeButton = new QRadioButton(i18n( "Change" ) + ":", this); + connect(changeButton, SIGNAL( clicked() ), SLOT( slotColorChange() )); + colorChangeButtons.insert(changeButton); + colorChangeLayout->addWidget(changeButton); + colorChangeValue = 0; + colorChangeSliderWidget = new QWidget(this); + QVBoxLayout* colorChangeSliderLayout = new QVBoxLayout(colorChangeSliderWidget, 1); + colorChangeSliderLayout->setMargin(0); + QSlider* colorChangeSlider = new QSlider(0, MAX_COLOR_CHANGE_VALUE, + MAX_COLOR_CHANGE_VALUE/4, colorChangeValue, QSlider::Horizontal, colorChangeSliderWidget); + colorChangeSlider->setTickInterval(colorChangeSlider->pageStep()); + colorChangeSlider->setTickmarks(QSlider::Above); + connect(colorChangeSlider, SIGNAL( valueChanged(int) ), SLOT( slotColorChangeValueChanged(int) )); + colorChangeSliderLayout->addWidget(colorChangeSlider); + QHBoxLayout* colorChangeSliderLabelsLayout = new QHBoxLayout(0); + QLabel* subtractLabel = new QLabel(i18n( "0" ), colorChangeSliderWidget); + colorChangeSliderLabelsLayout->addWidget(subtractLabel); + colorChangeSliderLabelsLayout->addStretch(10); + QLabel* addLabel = new QLabel(" " + i18n( "Replace" ), colorChangeSliderWidget); + colorChangeSliderLabelsLayout->addWidget(addLabel); + colorChangeSliderLayout->addLayout(colorChangeSliderLabelsLayout); + colorChangeLayout->addStretch(10); + colorChangeLayout->addWidget(colorChangeSliderWidget); + colorChangeLayout->addStretch(10); + layout->addLayout(colorChangeLayout, 10); + m_color.setComponents(RGB_MAX_COMPONENT_VALUE, RGB_MAX_COMPONENT_VALUE, RGB_MAX_COMPONENT_VALUE); + slotColorReplace(); + KSeparator* vLine = new KSeparator(KSeparator::VLine, this); + layout->addWidget(vLine); + layout->addWidget(textEditSelection, 1); + colorPatch = new KColorPatch(this); + connect(colorPatch, SIGNAL( colorChanged(const QColor&) ), SLOT( slotSetColor(const QColor&) )); + colorPatch->setMinimumSize(80, 64); + layout->addWidget(colorPatch, 10); + topLayout->addLayout(layout); +} +ColorSelector::~ColorSelector() { +} + +void ColorSelector::slotSetColor(Color color) { + m_color = color; + colorPatch->setColor(QColor( m_color.component(Color::RED_INDEX), + m_color.component(Color::GREEN_INDEX), + m_color.component(Color::BLUE_INDEX) )); + fComponentsMode = false; + emit valueChanged(&m_color); +} + +void ColorSelector::slotSetColor(Color* color) { + slotSetColor(*color); +} + +void ColorSelector::slotSetColor(const QColor& color) { + m_color.setComponent(Color::RED_INDEX, color.red()); + m_color.setComponent(Color::GREEN_INDEX, color.green()); + m_color.setComponent(Color::BLUE_INDEX, color.blue()); + fComponentsMode = false; + emit valueChanged(&m_color); +} + +void ColorSelector::scaledComponent(double* const component, const double componentDiff) { + double scaledComponentDiff = componentDiff* + pow(colorChangeValue*1.0/MAX_COLOR_CHANGE_VALUE, 2.0); + *component += scaledComponentDiff; + if(*component > RGB_MAX_COMPONENT_VALUE) + *component = RGB_MAX_COMPONENT_VALUE; + else if(*component < 0) + *component = 0; +} + +void ColorSelector::slotGradientSelectionChangeColor(Color* gradientSelectionColor) { + switch(colorChangeMode) { + case MODE_REPLACE: + slotSetColor(gradientSelectionColor); + break; + + case MODE_CHANGE: + gradientSelection->slotIgnoreSetValue(true); + double rComponent; + double gComponent; + double bComponent; + if(fComponentsMode) { + rComponent = fRComponent; + gComponent = fGComponent; + bComponent = fBComponent; + } else { + rComponent = m_color.component(Color::RED_INDEX); + gComponent = m_color.component(Color::GREEN_INDEX); + bComponent = m_color.component(Color::BLUE_INDEX); + } + double rDiff = gradientSelectionColor->component(Color::RED_INDEX) - rComponent; + double gDiff = gradientSelectionColor->component(Color::GREEN_INDEX) - gComponent; + double bDiff = gradientSelectionColor->component(Color::BLUE_INDEX) - bComponent; + /* + printf("base color = (%i %i %i) gradient color = (%i %i %i)\n", + rComponent, gComponent, bComponent, + gradientSelectionColor->getComponent(Color::RED_INDEX), + gradientSelectionColor->getComponent(Color::GREEN_INDEX), + gradientSelectionColor->getComponent(Color::BLUE_INDEX)); + */ + scaledComponent(&rComponent, rDiff); + scaledComponent(&gComponent, gDiff); + scaledComponent(&bComponent, bDiff); + Color newColor((int)( rComponent + 0.5 ), + (int)( gComponent + 0.5 ), (int)( bComponent + 0.5 ), ""); + slotSetColor(newColor); + fRComponent = rComponent; + fGComponent = gComponent; + fBComponent = bComponent; + fComponentsMode = true; + /* + printf("output color = (%i %i %i)\n", + rComponent, gComponent, bComponent); + */ + gradientSelection->slotIgnoreSetValue(false); + break; + } +} + +void ColorSelector::slotGradientSelectionSynchronizeColor() { + /** Notify the gradient selector to update its color */ + emit valueChanged(&m_color); +} + +const Color& ColorSelector::color() { + return m_color; +} + +void ColorSelector::slotColorReplace() { + colorChangeMode = MODE_REPLACE; + slotGradientSelectionSynchronizeColor(); + gradientSelection->enableSynchronizeColorButton(false); + colorChangeSliderWidget->setEnabled(false); +} + +void ColorSelector::slotColorChange() { + colorChangeMode = MODE_CHANGE; + gradientSelection->enableSynchronizeColorButton(true); + colorChangeSliderWidget->setEnabled(true); +} + +void ColorSelector::slotColorChangeValueChanged(int value) { + colorChangeValue = value; +} + +#include "colorselector.moc" diff --git a/kcoloredit/colorselector.h b/kcoloredit/colorselector.h new file mode 100644 index 00000000..21b5902b --- /dev/null +++ b/kcoloredit/colorselector.h @@ -0,0 +1,96 @@ +/*************************************************************************** + colorselector.h - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef COLORSELECTOR_H +#define COLORSELECTOR_H + +#include <qwidget.h> +#include <qcolor.h> +#include <qbuttongroup.h> +#include <kcolordialog.h> + +#include "color.h" +#include "gradientselection.h" + +/** Color selector widget + * @author Artur Rataj + */ +class ColorSelector : public QWidget { + Q_OBJECT + +public: + /** constructs a color selector widget */ + ColorSelector(QWidget *parent=0, const char *name=0); + ~ColorSelector(); + /** @return the selected color */ + const Color& color(); + +signals: + /** A signal that a color value has changed */ + void valueChanged(Color*); + +public slots: + /** Called if a color changed */ + void slotSetColor(Color color); + /** Called if a color changed */ + void slotSetColor(Color* color); + /** called if a color changed in the color patch */ + void slotSetColor(const QColor& color); + /** Called by the gradient selection, to replace or modify a color */ + void slotGradientSelectionChangeColor(Color* gradientSelectionColor); + /** Called by the gradient selection, to synchronize its color */ + void slotGradientSelectionSynchronizeColor(); + /** Called if color replace mode is chosen */ + void slotColorReplace(); + /** called if color change mode is chosen */ + void slotColorChange(); + /** Called if a color change value changed */ + void slotColorChangeValueChanged(int value); + +private: + /** Color change mode constants */ + enum { MODE_REPLACE = 0, + MODE_CHANGE = 1, + /** Maximum color change value */ + MAX_COLOR_CHANGE_VALUE = 16 }; + + /** A color change slider widget */ + QWidget* colorChangeSliderWidget; + /** Color change buttons button group widget */ + QButtonGroup colorChangeButtons; + /** A color patch widget */ + KColorPatch* colorPatch; + /** A gradient selection widget */ + GradientSelection* gradientSelection; + /** The current color */ + Color m_color; + /** Color change mode */ + int colorChangeMode; + /** Current color change value */ + int colorChangeValue; + /** Floating--point precision RGB components, for color change mode */ + double fRComponent; + double fGComponent; + double fBComponent; + /** Whether in the floating-point precision components mode */ + bool fComponentsMode; + + /** Scales a component according to componentDiff and colorChangeValue */ + void scaledComponent(double* const component, const double componentDiff); +}; + +#endif diff --git a/kcoloredit/editablestreamhistory.cpp b/kcoloredit/editablestreamhistory.cpp new file mode 100644 index 00000000..c299ed7a --- /dev/null +++ b/kcoloredit/editablestreamhistory.cpp @@ -0,0 +1,18 @@ +/*************************************************************************** + editablestream.cpp - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "editablestreamhistory.h" diff --git a/kcoloredit/editablestreamhistory.h b/kcoloredit/editablestreamhistory.h new file mode 100644 index 00000000..9fe59d99 --- /dev/null +++ b/kcoloredit/editablestreamhistory.h @@ -0,0 +1,107 @@ +/*************************************************************************** + editablestreamhistory.h - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef EDITABLESTREAMHISTORY_H +#define EDITABLESTREAMHISTORY_H + +/** A template class adding undo/redo history for EDITABLE_STREAM paste and cut + * methods + * @author Artur Rataj + */ +template <class EDITABLE_STREAM> class EditableStreamHistory { +public: + /** Constructs the class with stream as an EDITABLE_STREAM and + * a given number of undo levels + */ + EditableStreamHistory(EDITABLE_STREAM* stream, const int undoLevels); + ~EditableStreamHistory(); + /** Cuts a stream at index, of length length. + * Uses undo/redo history. + * @return A stream that has been cut out + */ + EDITABLE_STREAM cut(const int index, const int length); + /** Pastes a stream at index. Uses undo/redo history */ + void paste(const int index, EDITABLE_STREAM& pasteStream); + /** Replaces a stream at index. Uses undo/redo history */ + void replace(const int index, EDITABLE_STREAM& replaceStream); + /** @return Whether undo possible */ + bool undoPossible(); + /** @return Whether redo possible */ + bool redoPossible(); + /** Undoes if possible */ + void undo(); + /** Redoes if possible */ + void redo(); + /** @return A pointer to editableStream */ + EDITABLE_STREAM* editableStream(); + +protected: + /** An editable stream */ + EDITABLE_STREAM* m_editableStream; + /** A number of undo levels */ + int m_undoLevels; +}; + +template <class EDITABLE_STREAM> EditableStreamHistory<EDITABLE_STREAM>:: + EditableStreamHistory(EDITABLE_STREAM* stream, const int undoLevels) { + m_editableStream = stream; + m_undoLevels = undoLevels; +} +template <class EDITABLE_STREAM> EditableStreamHistory<EDITABLE_STREAM>::~EditableStreamHistory() { +} + +template <class EDITABLE_STREAM> EDITABLE_STREAM + EditableStreamHistory<EDITABLE_STREAM>::cut(const int index, const int length) { + EDITABLE_STREAM cut_stream = m_editableStream->cut(index, length); + return cut_stream; +} + +template <class EDITABLE_STREAM> void + EditableStreamHistory<EDITABLE_STREAM>::paste(const int index, EDITABLE_STREAM& pasteStream) { + m_editableStream->paste(index, pasteStream); +} + +template <class EDITABLE_STREAM> void + EditableStreamHistory<EDITABLE_STREAM>::replace(const int index, EDITABLE_STREAM& replaceStream) { + m_editableStream->cut(index, replaceStream.length()); + m_editableStream->paste(index, replaceStream); +} + +template <class EDITABLE_STREAM> bool + EditableStreamHistory<EDITABLE_STREAM>::undoPossible() { + return false; +} + +template <class EDITABLE_STREAM> bool + EditableStreamHistory<EDITABLE_STREAM>::redoPossible() { + return false; +} + +template <class EDITABLE_STREAM> void + EditableStreamHistory<EDITABLE_STREAM>::undo() { +} + +template <class EDITABLE_STREAM> void + EditableStreamHistory<EDITABLE_STREAM>::redo() { +} + +template <class EDITABLE_STREAM> EDITABLE_STREAM* + EditableStreamHistory<EDITABLE_STREAM>::editableStream() { + return m_editableStream; +} + +#endif diff --git a/kcoloredit/gradientselection.cpp b/kcoloredit/gradientselection.cpp new file mode 100644 index 00000000..a8927c7d --- /dev/null +++ b/kcoloredit/gradientselection.cpp @@ -0,0 +1,252 @@ +/*************************************************************************** + gradientselection.cpp - description + ------------------- + begin : Wed Jul 12 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <qlayout.h> +#include <qframe.h> +#include <qradiobutton.h> +#include <qcolor.h> +#include <klocale.h> + +#include "main.h" +#include "gradientselection.h" + +GradientSelection::GradientSelection(QWidget *parent, const char *name ) : QWidget(parent,name) { + QGridLayout* topLayout = new QGridLayout(this, 2, 2, 0); + QHBoxLayout* layout = new QHBoxLayout(0); + layout->setMargin(3); + xyColorSelector = new KXYColorSelector(this); + connect(xyColorSelector, SIGNAL( valueChanged(int, int) ), + SLOT( slotXyColorSelectorPosChanged(int, int) )); + layout->addWidget(xyColorSelector); + topLayout->addLayout(layout, 0, 0); + topLayout->setRowStretch(0, 10); + topLayout->setRowStretch(1, 0); + QVBoxLayout* xyColorSelectorLayout = new QVBoxLayout(); + QHBoxLayout* checkBoxLayout = new QHBoxLayout(); + checkBoxLayout->setMargin(0); + variableCheckBox = new QCheckBox(i18n( "Variable" ), this); + variableGlobalComponent = false; + connect(variableCheckBox, SIGNAL( toggled(bool) ), SLOT( slotSetVariableGlobalComponent(bool) )); + checkBoxLayout->addSpacing(2); + checkBoxLayout->addWidget(variableCheckBox); + xyColorSelectorLayout->addLayout(checkBoxLayout); + xyColorSelectorLayout->addStretch(10); + QHBoxLayout* buttonsLayout = new QHBoxLayout(); + synchronizeColorButton = new QPushButton(i18n( "Synchronize" ), this); + connect(synchronizeColorButton, SIGNAL( clicked() ), SLOT( slotSynchronizeColor() )); + buttonsLayout->addSpacing(2); + buttonsLayout->addWidget(synchronizeColorButton); + buttonsLayout->addStretch(10); + xyColorSelectorLayout->addLayout(buttonsLayout); + xyColorSelectorLayout->addSpacing(2); + topLayout->addLayout(xyColorSelectorLayout, 1, 0); + zColorSelector = new KZColorSelector(KZColorSelector::Vertical, this); + connect(zColorSelector, SIGNAL( valueChanged(int) ), + SLOT( slotZColorSelectorPosChanged(int) )); + zColorSelector->setFixedWidth(36); + topLayout->addWidget(zColorSelector, 0, 1); + QVBoxLayout* zColorSelectorLayout = new QVBoxLayout(0); + connect(&hsvButtons, SIGNAL( clicked(int) ), SLOT( slotSetColorSelectionMode(int) )); + QRadioButton* hRadioButton = new QRadioButton("H", this); + hsvButtons.insert(hRadioButton, H_COMPONENT); + zColorSelectorLayout->addWidget(hRadioButton); + QRadioButton* sRadioButton = new QRadioButton("S", this); + hsvButtons.insert(sRadioButton, S_COMPONENT); + zColorSelectorLayout->addWidget(sRadioButton); + QRadioButton* vRadioButton = new QRadioButton("V", this); + hsvButtons.insert(vRadioButton, V_COMPONENT); + vRadioButton->toggle(); + zColorSelectorLayout->addWidget(vRadioButton); + topLayout->addLayout(zColorSelectorLayout, 1, 1); + color.setComponents(RGB_MAX_COMPONENT_VALUE, RGB_MAX_COMPONENT_VALUE, RGB_MAX_COMPONENT_VALUE); + hComponent = -1; + sComponent = 0; + vComponent = HSV_MAX_V_VALUE; + slotIgnoreSetValue(false); + slotSetColorSelectionMode(V_COMPONENT); +} +GradientSelection::~GradientSelection(){ +} + +void GradientSelection::slotSetValue(Color* color) { + if(!ignoreSetValue && !color->equals( this->color )) { + this->color = *color; + int newHComponent; + int newSComponent; + int newVComponent; + QColor hsvColor(this->color.component(Color::RED_INDEX), + this->color.component(Color::GREEN_INDEX), + this->color.component(Color::BLUE_INDEX)); + hsvColor.hsv(&newHComponent, &newSComponent, &newVComponent); + hComponent = newHComponent; + sComponent = newSComponent; + vComponent = newVComponent; + updateXyColorSelector(false); + updateZColorSelector(); + } +} + +void GradientSelection::slotIgnoreSetValue(bool ignore) { + ignoreSetValue = ignore; +} + +void GradientSelection::updateXyColorSelector(const bool modeChanged) { + int xPos; + int yPos; + int component; + switch(zColorSelectorComponentIndex) { + case H_COMPONENT: + xPos = (int)(vComponent*( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 )/ + HSV_MAX_V_VALUE + 0.5); + yPos = (int)(sComponent*( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 )/ + HSV_MAX_S_VALUE + 0.5); + component = hComponent; + break; + + case S_COMPONENT: + xPos = (int)(hComponent*( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 )/ + HSV_MAX_H_VALUE + 0.5); + yPos = (int)(vComponent*( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 )/ + HSV_MAX_V_VALUE + 0.5); + if(variableGlobalComponent) + component = sComponent; + else + component = 240; + break; + + case V_COMPONENT: + xPos = (int)(hComponent*( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 )/ + HSV_MAX_H_VALUE + 0.5); + yPos = (int)(sComponent*( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 )/ + HSV_MAX_S_VALUE + 0.5); + if(variableGlobalComponent) + component = vComponent; + else + component = 192; + break; + + default: + xPos = 0; + yPos = 0; + component = 0; + break; + + } + if(xPos < 0) + xPos = 0; + if(yPos < 0) + yPos = 0; + if(modeChanged || xyColorSelector->globalComponent() != component) { + xyColorSelector->setGlobalComponent(component); + xyColorSelector->updateContents(); + } + xyColorSelector->setValues(xPos, yPos); +} + +void GradientSelection::updateZColorSelector() { + zColorSelector->setBaseColorHsv(hComponent, sComponent, vComponent); + zColorSelector->updatePointerPos(); + zColorSelector->updateContents(); +} + +void GradientSelection::slotSetColorSelectionMode(int mode) { + zColorSelectorComponentIndex = mode; + xyColorSelector->setType(zColorSelectorComponentIndex); + updateXyColorSelector(true); + switch(zColorSelectorComponentIndex) { + case H_COMPONENT: + zColorSelector->setType(KZColorSelector::TYPE_H); + variableCheckBox->setEnabled(false); + break; + + case S_COMPONENT: + zColorSelector->setType(KZColorSelector::TYPE_S); + variableCheckBox->setEnabled(true); + break; + + case V_COMPONENT: + zColorSelector->setType(KZColorSelector::TYPE_V); + variableCheckBox->setEnabled(true); + break; + + } + updateZColorSelector(); +} + +void GradientSelection::slotSetVariableGlobalComponent(bool variable) { + variableGlobalComponent = variable; + updateXyColorSelector(false); +} + +void GradientSelection::slotXyColorSelectorPosChanged(int x, int y) { + switch(zColorSelectorComponentIndex) { + case H_COMPONENT: + vComponent = (int)(x*1.0*HSV_MAX_V_VALUE/( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 ) + 0.5); + sComponent = (int)(y*1.0*HSV_MAX_S_VALUE/( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 ) + 0.5); + break; + + case S_COMPONENT: + hComponent = (int)(x*1.0*HSV_MAX_H_VALUE/( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 ) + 0.5); + vComponent = (int)(y*1.0*HSV_MAX_V_VALUE/( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 ) + 0.5); + break; + + case V_COMPONENT: + hComponent = (int)(x*1.0*HSV_MAX_H_VALUE/( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 ) + 0.5); + sComponent = (int)(y*1.0*HSV_MAX_S_VALUE/( KXYColorSelector::COMPONENT_SELECTION_RESOLUTION - 1 ) + 0.5); + break; + + } + QColor rgbColor; + rgbColor.setHsv(hComponent, sComponent, vComponent); + color.setComponents(rgbColor.red(), rgbColor.green(), rgbColor.blue()); + updateZColorSelector(); + emit valueChanged(&color); +} + +void GradientSelection::slotZColorSelectorPosChanged(int y) { + bool repaintZColorSelector = false; + switch(zColorSelectorComponentIndex) { + case H_COMPONENT: + hComponent = y; + break; + + case S_COMPONENT: + sComponent = y; + break; + + case V_COMPONENT: + vComponent = y; + break; + + } + QColor rgbColor; + rgbColor.setHsv(hComponent, sComponent, vComponent); + color.setComponents(rgbColor.red(), rgbColor.green(), rgbColor.blue()); + updateXyColorSelector(false); + if(repaintZColorSelector) + updateZColorSelector(); + emit valueChanged(&color); +} + +void GradientSelection::slotSynchronizeColor() { + emit synchronizeColor(); +} + +void GradientSelection::enableSynchronizeColorButton(bool enable) { + synchronizeColorButton->setEnabled(enable); +} +#include "gradientselection.moc" diff --git a/kcoloredit/gradientselection.h b/kcoloredit/gradientselection.h new file mode 100644 index 00000000..24a3c5e1 --- /dev/null +++ b/kcoloredit/gradientselection.h @@ -0,0 +1,106 @@ +/*************************************************************************** + gradientselection.h - description + ------------------- + begin : Wed Jul 12 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef GRADIENTSELECTION_H +#define GRADIENTSELECTION_H + +#include <qwidget.h> +#include <qcheckbox.h> +#include <qpushbutton.h> +#include <qbuttongroup.h> + +#include "kxycolorselector.h" +#include "kzcolorselector.h" +#include "color.h" + +/** A widget for selecting colors from gradients + * @author Artur Rataj + */ +class GradientSelection : public QWidget { + Q_OBJECT + +public: + /** Constructs the widget */ + GradientSelection(QWidget *parent=0, const char *name=0); + ~GradientSelection(); + /** Enables or disables the color synchronize button */ + void enableSynchronizeColorButton(bool enable); + +signals: + /** A signal that a color value has changed by edition */ + void valueChanged(Color*); + /** Synchronizes the widget color */ + void synchronizeColor(); + +public slots: + /** Sets a color */ + void slotSetValue(Color* color); + /** Whether to ignore the set value slot. Default is false. */ + void slotIgnoreSetValue(bool ignore); + +protected: + /** Components indices. If the gradient selector shows one of them, + * the two components selector should be in a mode indicated by a value + * of the appropriate index + */ + enum { H_COMPONENT = KXYColorSelector::TYPE_VS, + S_COMPONENT = KXYColorSelector::TYPE_HV, + V_COMPONENT = KXYColorSelector::TYPE_HS }; + + /** Variable global component checkbox */ + QCheckBox* variableCheckBox; + /** Synchronize color button */ + QPushButton* synchronizeColorButton; + /** HSV buttons button group widget */ + QButtonGroup hsvButtons; + /** The two components selector */ + KXYColorSelector* xyColorSelector; + /** The gradient selector */ + KZColorSelector* zColorSelector; + /** Whether the two component color selector global component is variable */ + bool variableGlobalComponent; + /** Whether to ignore the set value slot */ + bool ignoreSetValue; + /** The selected color */ + Color color; + /** The selected color H component */ + int hComponent; + /** The selected color S component */ + int sComponent; + /** The selected color V component */ + int vComponent; + /** The gradient selector component index */ + int zColorSelectorComponentIndex; + /** Updates two component selector colors */ + void updateXyColorSelector(const bool modeChanged); + /** Updates gradient selector colors */ + void updateZColorSelector(); + +protected slots: + /** Sets color selection mode */ + void slotSetColorSelectionMode(int mode); + /** Sets if the two component selector has a variable global component */ + void slotSetVariableGlobalComponent(bool variable); + /** Notifies that the two component color selector pointer position changed */ + void slotXyColorSelectorPosChanged(int x, int y); + /** Notifies that the gradient color selector pointer position changed */ + void slotZColorSelectorPosChanged(int y); + /** sends synchronizeColor signal */ + void slotSynchronizeColor(); +}; + +#endif diff --git a/kcoloredit/hi16-app-kcolorchooser.png b/kcoloredit/hi16-app-kcolorchooser.png Binary files differnew file mode 100644 index 00000000..eeb387b3 --- /dev/null +++ b/kcoloredit/hi16-app-kcolorchooser.png diff --git a/kcoloredit/hi16-app-kcoloredit.png b/kcoloredit/hi16-app-kcoloredit.png Binary files differnew file mode 100644 index 00000000..c0a67bb9 --- /dev/null +++ b/kcoloredit/hi16-app-kcoloredit.png diff --git a/kcoloredit/hi22-app-kcolorchooser.png b/kcoloredit/hi22-app-kcolorchooser.png Binary files differnew file mode 100644 index 00000000..faa5080f --- /dev/null +++ b/kcoloredit/hi22-app-kcolorchooser.png diff --git a/kcoloredit/hi32-app-kcoloredit.png b/kcoloredit/hi32-app-kcoloredit.png Binary files differnew file mode 100644 index 00000000..e5aa87cb --- /dev/null +++ b/kcoloredit/hi32-app-kcoloredit.png diff --git a/kcoloredit/imageselection.cpp b/kcoloredit/imageselection.cpp new file mode 100644 index 00000000..39a8f2f0 --- /dev/null +++ b/kcoloredit/imageselection.cpp @@ -0,0 +1,28 @@ +/*************************************************************************** + imageselection.cpp - description + ------------------- + begin : Wed Jul 12 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "imageselection.h" + +ImageSelection::ImageSelection(QWidget *parent, const char *name ) : QWidget(parent,name) { +} +ImageSelection::~ImageSelection(){ +} + +void ImageSelection::slotSetValue(Color* color) { + this->color = *color; +} +#include "imageselection.moc" diff --git a/kcoloredit/imageselection.h b/kcoloredit/imageselection.h new file mode 100644 index 00000000..3137fec7 --- /dev/null +++ b/kcoloredit/imageselection.h @@ -0,0 +1,49 @@ +/*************************************************************************** + imageselection.h - description + ------------------- + begin : Wed Jul 12 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef IMAGESELECTION_H +#define IMAGESELECTION_H + +#include <qwidget.h> + +#include "color.h" + +/** This is a widget for selecting colors from an image + * @author Artur Rataj + */ +class ImageSelection : public QWidget { + Q_OBJECT + +public: + /** constructs the widget */ + ImageSelection(QWidget *parent=0, const char *name=0); + ~ImageSelection(); + +signals: + /** A signal that a color value has changed by edition */ + void valueChanged(Color*); + +public slots: + /** Sets a color */ + void slotSetValue(Color* color); + +protected: + /** The selected color */ + Color color; +}; + +#endif diff --git a/kcoloredit/kcolorchooser.cpp b/kcoloredit/kcolorchooser.cpp new file mode 100644 index 00000000..bf1204fb --- /dev/null +++ b/kcoloredit/kcolorchooser.cpp @@ -0,0 +1,70 @@ +/* +This file is part of KDE + + Copyright (C) 1998-2000 Waldo Bastian ([email protected]) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include <iostream> + +#include <kapplication.h> +#include <kcmdlineargs.h> +#include <kaboutdata.h> +#include <klocale.h> + +#include "kcolordialog.h" + +static const char description[] = + I18N_NOOP("KDE Color Chooser"); + +static const char version[] = "v1.0.1"; + +static KCmdLineOptions options[] = +{ + { "print", I18N_NOOP("Print the selected color to stdout"), 0 }, + KCmdLineLastOption +}; + +int main(int argc, char *argv[]) +{ + KLocale::setMainCatalogue("kdelibs"); + KAboutData aboutData( "kcolorchooser", I18N_NOOP("KColorChooser"), + version, description, KAboutData::License_BSD, + "(c) 2000, Waldo Bastian"); + aboutData.addAuthor("Waldo Bastian",0, "[email protected]"); + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); + + KApplication app; + + KColorDialog dlg; + + dlg.setColor(Qt::blue); // Just a color + + app.connect(&dlg, SIGNAL(finished()), SLOT(quit())); + + dlg.show(); + app.exec(); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + const QColor c = dlg.color(); + if ( args->isSet("print") && c.isValid() ) { + std::cout << c.name().utf8().data() << std::endl; + } +} diff --git a/kcoloredit/kcolorchooser.desktop b/kcoloredit/kcolorchooser.desktop new file mode 100644 index 00000000..37d7b075 --- /dev/null +++ b/kcoloredit/kcolorchooser.desktop @@ -0,0 +1,108 @@ +[Desktop Entry] +Type=Application +Exec=kcolorchooser %i %m +Icon=kcolorchooser +Path= +Terminal=false +DocPath=kcoloredit/index.html +GenericName=Color Chooser +GenericName[af]=Kleur Kieser +GenericName[ar]=برنامج اختيار الألوان +GenericName[bg]=Избор на цвят +GenericName[br]=Dibaber livioù +GenericName[bs]=Izbornik boja +GenericName[ca]=Elecció de colors +GenericName[cs]=Výběr barev +GenericName[cy]=Dewis Lliwiau +GenericName[da]=Farvevælger +GenericName[de]=Farbauswahl +GenericName[el]=Επιλογέας χρωμάτων +GenericName[en_GB]=Colour Chooser +GenericName[eo]=Ilo por elekti koloron +GenericName[es]=Selector de colores +GenericName[et]=Värvivalija +GenericName[eu]=Kolore hautatzailea +GenericName[fa]=انتخابکنندۀ رنگ +GenericName[fi]=Värivalitsin +GenericName[fr]=Sélecteur de couleur +GenericName[gl]=Selecionador de cores +GenericName[he]=בוחר צבעים +GenericName[hi]=रंग चयनक +GenericName[hr]=Izbornik boja +GenericName[hu]=Színválasztó +GenericName[is]=Litavalstól +GenericName[it]=Selettore di colori +GenericName[ja]=色の選択 +GenericName[kk]=Түсті таңдау +GenericName[km]=កម្មវិធីជ្រើសពណ៌ +GenericName[lt]=Spalvų parinkiklis +GenericName[lv]=Krāsu Izvēlētājs +GenericName[mk]=Избирач на бои +GenericName[ms]=Pemilih Warna +GenericName[mt]=Agħżel Kulur +GenericName[nb]=Fargevelger +GenericName[nds]=Klöörutwahl +GenericName[ne]=रङ चयनकर्ता +GenericName[nl]=Kleurenkiezer +GenericName[nn]=Fargeveljar +GenericName[pa]=ਰੰਗ ਸੰਰਚਨਾ +GenericName[pl]=Wybór koloru +GenericName[pt]=Selector de Cores +GenericName[pt_BR]=Seletor de Cores +GenericName[ro]=Selector de culori +GenericName[ru]=Выбор цвета +GenericName[se]=Ivdneválljejeaddji +GenericName[sk]=Výber farieb +GenericName[sl]=Izbirnik barv +GenericName[sr]=Бирач боја +GenericName[sr@Latn]=Birač boja +GenericName[sv]=Färgväljare +GenericName[ta]=வண்ணத் தேர்வு +GenericName[tg]=Интихоби ранг +GenericName[th]=เครื่องมือเลือกสีของ KDE +GenericName[tr]=Renk Seçici +GenericName[uk]=Селектор кольорів +GenericName[uz]=Rang tanlovchi +GenericName[uz@cyrillic]=Ранг танловчи +GenericName[ven]=Munangi wa Muvhala +GenericName[wa]=Tchoezixheu di coleurs +GenericName[xh]=Mkhethi Wombala +GenericName[zh_CN]=颜色选择程序 +GenericName[zh_HK]=顏色選擇器 +GenericName[zh_TW]=顏色選擇程式 +GenericName[zu]=Umkhethi Wombala +Name=KColorChooser +Name[af]=K-kleur-kieser +Name[ar]=برنامج KColorChooser +Name[ca]=Elecció de colors +Name[cs]=Výběr barev +Name[cy]=KDewisLliw +Name[eo]=Kolorelektilo +Name[fi]=Värivalitsin +Name[hi]=के-कलर-चूसर +Name[hr]=Izbornik boja +Name[is]=Litaval +Name[lv]=KKrāsuIzvēlētājs +Name[nb]=Fargevelger +Name[ne]=केडीई रङ चयनकर्ता +Name[nn]=KDE-fargeveljar +Name[nso]=KMokgethi wa Mmala +Name[pa]=ਕੇਰੰਗਚੋਣਕਾਰ +Name[pl]=Wybór koloru +Name[pt_BR]=KSeletor de Cores +Name[ro]=Selector culori +Name[se]=KDE-ivdneválljejeaddji +Name[sv]=Kcolorchooser +Name[ta]=கேவண்ணத் தேர்வு +Name[th]=เครื่องมือเลือกสี - K +Name[tr]=K Renk Seçici +Name[uk]=Селектор кольорів +Name[uz]=Rang tanlovchi +Name[uz@cyrillic]=Ранг танловчи +Name[ven]=Tshinangi tsha muvhala tsha K +Name[xh]=Umkhethi Wombala i K +Name[zh_TW]=KColorChooser 顏色選擇器 +Name[zu]=Umkhethi Wombala ka K + +X-DCOP-ServiceType=Multi +Categories=Qt;KDE;Graphics;X-KDE-More; diff --git a/kcoloredit/kcoloredit.cpp b/kcoloredit/kcoloredit.cpp new file mode 100644 index 00000000..a5582436 --- /dev/null +++ b/kcoloredit/kcoloredit.cpp @@ -0,0 +1,363 @@ +/*************************************************************************** + kcoloredit.cpp - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// include files for QT +#include <qdir.h> +#include <qprinter.h> +#include <qpainter.h> + +// include files for KDE +#include <kiconloader.h> +#include <kmessagebox.h> +#include <kfiledialog.h> +#include <kmenubar.h> +#include <klocale.h> +#include <kcolordialog.h> +#include <kconfig.h> +#include <kdebug.h> + +// application specific includes +#include "kcoloredit.h" +#include "kcoloreditview.h" +#include "kcoloreditdoc.h" +#include "loadpalettedlg.h" +#include "resource.h" +#include <kpopupmenu.h> +#include <kstatusbar.h> + + +KColorEditApp::KColorEditApp() : KMainWindow(0) { + config=kapp->config(); + + /////////////////////////////////////////////////////////////////// + // call inits to invoke all other construction parts + initActions(); + initStatusBar(); + initDocument(); + initView(); + + resize(606,400); + setupGUI(); + + readOptions(); + + gettingColorFromScreen = false; +} + +KColorEditApp::~KColorEditApp() { +} + +void KColorEditApp::initActions() +{ + // File actiojns + KStdAction::openNew( this, SLOT( slotFileNew() ), actionCollection() ); + KStdAction::open( this, SLOT( slotFileOpen() ), actionCollection() ); + KStdAction::saveAs( this, SLOT( slotFileSaveAs() ), actionCollection() ); + KStdAction::close( this, SLOT( slotClose() ), actionCollection() ); + KStdAction::quit( this, SLOT( slotQuit() ), actionCollection() ); + m_actSave = KStdAction::save( this, SLOT( slotFileSave() ), + actionCollection() ); + m_actRecent = KStdAction::openRecent( this, + SLOT( slotFileOpenRecent( const KURL& ) ), actionCollection() ); + + ( void ) new KAction( i18n("New &Window"), kapp->miniIcon(), KShortcut(), + this, SLOT( slotFileNewWindow() ), actionCollection(), + "file_new_window" ); + + // Edit actions + m_actCut = KStdAction::cut( this, SLOT( slotEditCut() ), + actionCollection() ); + m_actCopy = KStdAction::copy( this, SLOT( slotEditCopy() ), + actionCollection() ); + m_actPaste = KStdAction::paste( this, SLOT( slotEditPaste() ), + actionCollection() ); + + m_actPaste->setEnabled( false ); + + // Color Menu + m_actNames = new KToggleAction( i18n("Show &Color Names"), KShortcut(), this, + SLOT( slotViewColorNames() ), actionCollection(), + "color_view_names" ); + m_actNames->setCheckedState(i18n("Hide &Color Names")); + m_actPalette = new KAction( i18n("From &Palette"), KShortcut(), this, + SLOT( slotColorFromPalette() ), actionCollection(), + "color_from_palette" ); + ( void ) new KAction( i18n("From &Screen"), KShortcut(), this, + SLOT( slotColorFromScreen() ), actionCollection(), + "color_from_screen" ); +} + +void KColorEditApp::initStatusBar() +{ + statusBar()->insertItem(i18n("Ready."), ID_STATUS_MSG, 1); + statusBar()->setItemAlignment( ID_STATUS_MSG, Qt::AlignLeft ); +} + +void KColorEditApp::initDocument() +{ + doc = new KColorEditDoc(this); + doc->newDocument(); + + connect( doc, SIGNAL( selectionChanged( int, int ) ), + SLOT( slotSelectionChanged( int, int ) ) ); + connect( doc, SIGNAL( clipboardChanged() ), + SLOT( slotClipboardChanged() ) ); + connect( doc, SIGNAL( modified( bool ) ), + SLOT( slotModified( bool ) ) ); + connect( doc, SIGNAL( paletteAvailable( bool ) ), + SLOT( slotPaletteAvailable( bool ) ) ); +} + +void KColorEditApp::initView() +{ + //////////////////////////////////////////////////////////////////// + // create the main widget here that is managed by KMainWindow's view-region + // and connect the widget to your document to display document contents. + + view = new KColorEditView(this); + doc->addView(view); + setCentralWidget(view); + setCaption(doc->title()); +} + +void KColorEditApp::openDocumentFile(const char* _cmdl) +{ + doc->openDocument(_cmdl); +} + + +KColorEditDoc *KColorEditApp::document() const +{ + return doc; +} + +void KColorEditApp::saveOptions() +{ + saveMainWindowSettings( config, "MainWindowSettings" ); + m_actRecent->saveEntries( config ); + + config->setGroup("KColorEdit Options"); + config->writeEntry("ColorNames", viewColorNames); +} + +void KColorEditApp::readOptions() +{ + applyMainWindowSettings( config, "MainWindowSettings" ); + m_actRecent->loadEntries( config ); + + config->setGroup("KColorEdit Options"); + + viewColorNames = config->readBoolEntry("ColorNames", false); + m_actNames->setChecked(viewColorNames); + doc->slotChangeViewMode(viewColorNames); +} + +bool KColorEditApp::queryClose() +{ + return doc->saveModified(); +} + +bool KColorEditApp::queryExit() +{ + saveOptions(); + return true; +} + +///////////////////////////////////////////////////////////////////// +// SLOT IMPLEMENTATION +///////////////////////////////////////////////////////////////////// + +void KColorEditApp::slotSelectionChanged( int begin, int end ) +{ + m_actCut->setEnabled( begin != end ); + m_actCopy->setEnabled( begin != end ); +} + +void KColorEditApp::slotClipboardChanged() +{ + m_actPaste->setEnabled( true ); +} + +void KColorEditApp::slotModified( bool b ) +{ + m_actSave->setEnabled( b ); +} + +void KColorEditApp::slotPaletteAvailable( bool b ) +{ + m_actPalette->setEnabled( b ); +} + +void KColorEditApp::slotFileNewWindow() +{ + KColorEditApp *new_window= new KColorEditApp(); + new_window->show(); +} + +void KColorEditApp::slotFileNew() +{ + if(doc->saveModified()) { + doc->newDocument(); + + setCaption(doc->title()); + } +} + +void KColorEditApp::slotFileOpen() { + if(doc->saveModified()) { + LoadPaletteDlg dialog(this); + if(dialog.exec()) { + QString fileToOpen = dialog.getFileName(); + if(!fileToOpen.isEmpty()) + { + if(!doc->openDocument( fileToOpen )) { + KMessageBox::sorry(0, doc->errorString()); + } else { + setCaption(doc->title()); + m_actRecent->addURL( KURL::fromPathOrURL( fileToOpen ) ); + } + } + } + } +} + +void KColorEditApp::slotFileOpenRecent( const KURL & url ) +{ + if(doc->saveModified()) { + doc->openDocument( url.path() ); + setCaption(doc->title()); + } +} + +void KColorEditApp::slotFileSave() +{ + if(!doc->saveDocument( doc->absFilePath() )) + slotFileSaveAs(); + //KMessageBox::sorry(0, doc->getErrorString()); +} + +bool KColorEditApp::slotFileSaveAs() +{ + bool result = true; + + while(result) { + QString newName=KFileDialog::getSaveFileName(lastSavePaletteAsFileDir, + "*|" + i18n("All Files"), this, i18n("Save As")); + if(newName.isEmpty()) + result = false; + else { + QFileInfo saveAsInfo(newName); + if(!saveAsInfo.exists() || + KMessageBox::questionYesNo( this, + i18n("A Document with this name already exists.\n" + "Do you want to overwrite it?"), + i18n("Warning"), i18n("Overwrite"), KStdGuiItem::cancel() ) == KMessageBox::Yes) { + if(!doc->saveDocument( newName )) { + KMessageBox::sorry(0, doc->errorString()); + result = false; + } else { + doc->setTitle(saveAsInfo.fileName()); + doc->setAbsFilePath(saveAsInfo.absFilePath()); + setCaption(doc->title()); + lastSavePaletteAsFileDir = saveAsInfo.absFilePath(); + m_actRecent->addURL( KURL( newName ) ); + break; + } + } + } + } + + return result; +} + +void KColorEditApp::slotClose() +{ + close(); +} + +void KColorEditApp::slotFilePrint() +{ + QPrinter printer; + if (printer.setup(this)) + { + view->print(&printer); + } +} + +void KColorEditApp::slotQuit() +{ + saveOptions(); + // close the first window, the list makes the next one the first again. + // This ensures that queryClose() is called on each window to ask for closing + KMainWindow* w; + if(memberList) + { + for(w=memberList->first(); w!=0; w=memberList->next()) + { + // only close the window if the closeEvent is accepted. If the user presses Cancel on the saveModified() dialog, + // the window and the application stay open. + if(!w->close()) + break; + } + } +} + +void KColorEditApp::slotEditCut() +{ + doc->cut(); +} + +void KColorEditApp::slotEditCopy() +{ + doc->copy(); +} + +void KColorEditApp::slotEditPaste() +{ + doc->paste(); +} + +void KColorEditApp::slotColorFromPalette() { + view->chooseColor(doc->paletteHistory()->editableStream()-> + color( doc->paletteCursorPos() )); +} + +void KColorEditApp::slotColorFromScreen() { + gettingColorFromScreen = true; + grabMouse(crossCursor); + grabKeyboard(); +} + +void KColorEditApp::slotViewColorNames() +{ + viewColorNames = m_actNames->isChecked(); + doc->slotChangeViewMode(viewColorNames); +} + +void KColorEditApp::mouseReleaseEvent(QMouseEvent* event) { + if(gettingColorFromScreen) { + gettingColorFromScreen = false; + releaseMouse(); + releaseKeyboard(); + QColor rgbColor = KColorDialog::grabColor(event->globalPos()); + color.setComponents(rgbColor.red(), rgbColor.green(), rgbColor.blue()); + view->chooseColor(&color); + } else + KMainWindow::mouseReleaseEvent(event); +} + +#include "kcoloredit.moc" diff --git a/kcoloredit/kcoloredit.desktop b/kcoloredit/kcoloredit.desktop new file mode 100644 index 00000000..8a27dce8 --- /dev/null +++ b/kcoloredit/kcoloredit.desktop @@ -0,0 +1,96 @@ +[Desktop Entry] +Type=Application +Exec=kcoloredit %i %m %U +Icon=kcoloredit +Path= +Terminal=false +DocPath=kcoloredit/index.html +GenericName=Color Palette Editor +GenericName[af]=Kleur Palet Redigeerder +GenericName[ar]=محرر لوحة الألوان +GenericName[bg]=Редактор на цветове +GenericName[br]=Aozer livaoueg +GenericName[bs]=Editor palete boja +GenericName[ca]=Editor de la paleta de colors +GenericName[cs]=Editor palety barev +GenericName[cy]=Golygydd Palet Lliwiau +GenericName[da]=Farvepaletredigering +GenericName[de]=Editor für Farbpaletten +GenericName[el]=Επεξεργαστής παλέτας χρωμάτων +GenericName[en_GB]=Colour Palette Editor +GenericName[eo]=Paletroredaktilo +GenericName[es]=Editor de paleta de color +GenericName[et]=Värvipaleti redaktor +GenericName[eu]=Koloreko paleta editorea +GenericName[fa]=ویرایشگر پالت رنگ +GenericName[fi]=Väripalettien muokkain +GenericName[fr]=Éditeur de palette de couleurs +GenericName[gl]=Editor de paletas de cores +GenericName[he]=עורך לוחות צבעים +GenericName[hi]=रंग पट्टिका संपादक +GenericName[hr]=Uređivač palete +GenericName[hu]=Palettaszerkesztő +GenericName[is]=Sýsla með litaspjöld +GenericName[it]=Editor di tavolozza +GenericName[ja]=カラーパレットエディタ +GenericName[kk]=Түстер палитрасын өңдеу +GenericName[km]=កម្មវិធីនិពន្ធក្ដារលាយពណ៌ +GenericName[lt]=Spalvų paletės redaktorius +GenericName[lv]=Krāsu Paletes Redaktors +GenericName[mk]=Уредувач на палета +GenericName[ms]=Editor Palet Warna +GenericName[mt]=Editur tal-palett ta' kului +GenericName[nb]=Palett-redigerer +GenericName[nds]=Klörensett-Editor +GenericName[ne]=रङदानी सम्पादक +GenericName[nl]=Kleurenpaletbewerker +GenericName[nn]=Palettredigering +GenericName[pa]=ਰੰਗ ਪੱਟੀ ਸੰਪਾਦਕ +GenericName[pl]=Edytor palety (kolorów) +GenericName[pt]=Editor de Paletas de Cores +GenericName[pt_BR]=Editor de Paleta de Cores +GenericName[ro]=Editor paletă de culori +GenericName[ru]=Редактор палитры +GenericName[se]=Ivdnepaleahta doaimmaheaddji +GenericName[sk]=Editor palety farieb +GenericName[sl]=Urejevalnik barvne palete +GenericName[sr]=Уређивач палете боја +GenericName[sr@Latn]=Uređivač palete boja +GenericName[sv]=Färgpaletteditor +GenericName[ta]=வண்ணகளஞ்சியம் +GenericName[tg]=Муҳаррири палитра +GenericName[th]=เครื่องมือแก้ไขจานสีของ KDE +GenericName[tr]=Renk Paleti Düzenleyici +GenericName[uk]=Редактор палітри кольорів +GenericName[ven]=Musengulusi wa phalete ya muvhala +GenericName[wa]=Aspougneu del palete di coleurs +GenericName[zh_CN]=调色板编辑器 +GenericName[zh_HK]=調色板編輯器 +GenericName[zh_TW]=調色板編輯器 +GenericName[zu]=Umhleli Wombala we Palette +Name=KColorEdit +Name[af]=K-kleur-redigeer +Name[ar]=برنامج KColorEdit +Name[cs]=Editor barev +Name[cy]=KGolyguLliw +Name[eo]=Kolorredaktilo +Name[hi]=के-कलर-एडिट +Name[hr]=Uređivač boja +Name[lv]=KKrāsuRedaktors +Name[ne]=केडीई रङ सम्पादन +Name[nso]=KPhetoso ya Mmala +Name[pa]=ਕੇਰੰਗ ਸੰਪਾਦਕ +Name[pl]=Edytor kolorów +Name[pt_BR]=KEditor de Cores +Name[ro]=Editor culori +Name[sv]=Kcoloredit +Name[ta]=கேவண்ணம் திருத்தம் +Name[th]=แก้ไขค่าสี - K +Name[tr]=K Renk Düzenleyici +Name[ven]=U sengulusa muvhala ha K +Name[xh]=Umhleli Wombala ye K +Name[zh_TW]=KColorEdit 顏色編輯器 +Name[zu]=Umhleli Wombala ka K + +X-DCOP-ServiceType=Multi +Categories=Qt;KDE;Graphics;X-KDE-More; diff --git a/kcoloredit/kcoloredit.h b/kcoloredit/kcoloredit.h new file mode 100644 index 00000000..cd69cdaf --- /dev/null +++ b/kcoloredit/kcoloredit.h @@ -0,0 +1,192 @@ +/*************************************************************************** + kcoloredit.h - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef KCOLOREDIT_H +#define KCOLOREDIT_H + + +#include <config.h> + +// include files for Qt +#include <qevent.h> +#include <qstringlist.h> + +// include files for KDE +#include <kapplication.h> +#include <kmainwindow.h> +#include <kaction.h> + +// application specific includes +#include "color.h" + +class KColorEditDoc; +class KColorEditView; + +/** + * The base class for KColorEdit application windows. It sets up the main + * window and reads the config file as well as providing a menubar, toolbar + * and statusbar. An instance of KColorEditView creates your center view, which is connected + * to the window's Doc object. + * KColorEditApp reimplements the methods that KMainWindow provides for main window handling and supports + * full session management as well as keyboard accelerator configuration by using KAccel. + * @see KMainWindow + * @see KApplication + * @see KConfig + * @see KAccel + * + * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team. + * @version KDevelop version 0.4 code generation + */ +class KColorEditApp : public KMainWindow +{ + Q_OBJECT + + friend class KColorEditView; + + public: + /** construtor of KColorEditApp, calls all init functions to create the application. + * @see initMenuBar initToolBar + */ + KColorEditApp(); + ~KColorEditApp(); + + /** opens a file specified by commandline option + */ + void openDocumentFile(const char *_cmdl=0); + /** returns a pointer to the current document connected to the KMainWindow instance and is used by + * the View class to access the document object's methods + */ + KColorEditDoc *document() const; + + protected: + /** save general Options like all bar positions and status as well as the geometry and the recent file list to the configuration + * file + */ + void saveOptions(); + /** read general Options again and initialize all variables like the recent file list + */ + void readOptions(); + + void initActions(); + + /** initMenuBar creates the menubar and inserts the menupopups as well as creating the helpMenu. + * @see KApplication#getHelpMenu + */ + void initStatusBar(); + /** initializes the document object of the main window that is connected to the view in initView(). + * @see initView(); + */ + void initDocument(); + /** creates the centerwidget of the KMainWindow instance and sets it as the view + */ + void initView(); + /** queryClose is called by KMainWindow on each closeEvent of a window. Against the + * default implementation (only returns true), this calles saveModified() on the document object to ask if the document shall + * be saved if Modified; on cancel the closeEvent is rejected. + * @see KMainWindow#queryClose + * @see KMainWindow#closeEvent + */ + virtual bool queryClose(); + /** queryExit is called by KMainWindow when the last window of the application is going to be closed during the closeEvent(). + * Against the default implementation that just returns true, this calls saveOptions() to save the settings of the last window's + * properties. + * @see KMainWindow#queryExit + * @see KMainWindow#closeEvent + */ + virtual bool queryExit(); + + void mouseReleaseEvent(QMouseEvent* event); + + public slots: + + void slotFileNewWindow(); + /** clears the document in the actual view to reuse it as the new document */ + void slotFileNew(); + /** open a file and load it into the document*/ + void slotFileOpen(); + /** opens a file from the recent files menu */ + void slotFileOpenRecent( const KURL & ); + /** save a document */ + void slotFileSave(); + /** save a document by a new filename + * @return whether the file has been saved + */ + bool slotFileSaveAs(); + /** asks for saving if the file is modified, then closes the actual file and window*/ + void slotClose(); + /** print the actual file */ + void slotFilePrint(); + /** closes all open windows by calling close() on each memberList item until the list is empty, then quits the application. + * If queryClose() returns false because the user canceled the saveModified() dialog, the closing breaks. + */ + void slotQuit(); + /** put the marked text/object into the clipboard and remove + * it from the document + */ + void slotEditCut(); + /** put the marked text/object into the clipboard + */ + void slotEditCopy(); + /** paste the clipboard into the document + */ + void slotEditPaste(); + /** get a color from palette + */ + void slotColorFromPalette(); + /** get a color from screen + */ + void slotColorFromScreen(); + /** copies a color to clipboard + */ + void slotViewColorNames(); + /** changes the statusbar contents for the standard label permanently, used to indicate current actions. + * @param text the text that is displayed in the statusbar + */ + + void slotSelectionChanged( int, int ); + void slotClipboardChanged(); + void slotModified( bool ); + void slotPaletteAvailable( bool ); + + private: + + /** the configuration object of the application */ + KConfig *config; + + KAction *m_actSave, *m_actCut, *m_actCopy, *m_actPaste, *m_actPalette; + KToggleAction *m_actNames; + KRecentFilesAction *m_actRecent; + + /** view is the main widget which represents your working area. The View + * class should handle all events of the view widget. It is kept empty so + * you can create your view according to your application's needs by + * changing the view class. + */ + KColorEditView *view; + /** doc represents your actual document and is created only once. It keeps + * information such as filename and does the serialization of your files. + */ + KColorEditDoc *doc; + /** Whether in getting a color from screen */ + bool gettingColorFromScreen; + /** A color taken from screen */ + Color color; + /** Whether to view color names */ + bool viewColorNames; +}; + +#endif // KCOLOREDIT_H diff --git a/kcoloredit/kcoloreditdoc.cpp b/kcoloredit/kcoloreditdoc.cpp new file mode 100644 index 00000000..536300a5 --- /dev/null +++ b/kcoloredit/kcoloreditdoc.cpp @@ -0,0 +1,293 @@ +/*************************************************************************** + kcoloreditdoc.cpp - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// include files for Qt +#include <qdir.h> +#include <qfileinfo.h> +#include <qwidget.h> +#include <qclipboard.h> + +// include files for KDE +#include <klocale.h> +#include <kmessagebox.h> + +// application specific includes +#include "kcoloreditdoc.h" +#include "kcoloredit.h" +#include "kcoloreditview.h" +#include "resource.h" + +KColorEditDoc::KColorEditDoc(QWidget *parent, const char *name) : QObject(parent, name), + m_palette(), m_paletteHistory(&m_palette, 0) { + m_pViewList = new QPtrList<KColorEditView>(); + m_pViewList->setAutoDelete(true); +} + +KColorEditDoc::~KColorEditDoc() +{ +} + +void KColorEditDoc::addView(KColorEditView *view) +{ + m_pViewList->append(view); +} + +void KColorEditDoc::removeView(KColorEditView *view) +{ + m_pViewList->remove(view); +} + +void KColorEditDoc::setModified(bool b) { + m_modified = b; + + emit modified( b ); +} + +void KColorEditDoc::setAbsFilePath(const QString &filename) +{ + m_absFilePath=filename; +} + +const QString &KColorEditDoc::absFilePath() const +{ + return m_absFilePath; +} + +void KColorEditDoc::setTitle(const QString &_t) +{ + m_title=_t; +} + +const QString &KColorEditDoc::title() const +{ + return m_title; +} + +void KColorEditDoc::slotRedrawAllViews(KColorEditView *sender, bool newDocument) { + KColorEditView *w; + if(m_pViewList) + { + for(w=m_pViewList->first(); w!=0; w=m_pViewList->next()) + { + if(w!=sender) + w->redraw(newDocument); + } + } +} + +void KColorEditDoc::slotChangeViewMode(bool viewColorNames) { + KColorEditView *w; + if(m_pViewList) + { + for(w=m_pViewList->first(); w!=0; w=m_pViewList->next()) + { + w->slotViewColorNames(viewColorNames); + } + } +} + +bool KColorEditDoc::saveModified() +{ + bool completed=true; + + if(m_modified) + { + KColorEditApp *window=(KColorEditApp *) parent(); + int want_save = KMessageBox::warningYesNoCancel(window, + i18n("The current file has been modified.\n" + "Do you want to save it?"), QString::null, KStdGuiItem::save(), i18n("Do Not Save")); + switch(want_save) + { + case KMessageBox::Yes: + if (title() == i18n("Untitled")) + { + completed = window->slotFileSaveAs(); + } + else + { + completed = saveDocument(absFilePath()); + }; + if(!completed) + KMessageBox::sorry(0, errorString()); + break; + + case KMessageBox::No: + completed=true; + break; + + case KMessageBox::Cancel: + completed=false; + break; + + default: + completed=false; + break; + } + } + + return completed; +} + +void KColorEditDoc::closeDocument() +{ + deleteContents(); +} + +bool KColorEditDoc::newDocument() +{ + deleteContents(); + setModified(false); + setAbsFilePath( QDir::homeDirPath() ); + setTitle( i18n("Untitled") ); + setPaletteCursorPos(0); + setPaletteSelection(0, 0); + slotRedrawAllViews(0, true); + return true; +} + +bool KColorEditDoc::openDocument(const QString& filename) { + if(filename.isEmpty()) + return newDocument(); + else { + deleteContents(); + QFileInfo fileInfo(filename); + setAbsFilePath( fileInfo.absFilePath() ); + if(!m_palette.load( absFilePath() )) { + setErrorString(m_palette.errorString()); + return false; + } + setModified(false); + setTitle( fileInfo.fileName() ); + setPaletteCursorPos(m_palette.length()); + setPaletteSelection(0, 0); + slotRedrawAllViews(0, true); + KColorEditApp *window=(KColorEditApp*)parent(); + window->setCaption(m_title); + } + return true; +} + +bool KColorEditDoc::saveDocument(const QString& filename) { + if(!m_palette.save( filename )) { + setErrorString(m_palette.errorString()); + return false; + } + setModified(false); + return true; +} + +void KColorEditDoc::deleteContents() { + m_palette.deleteContents(); +} + +void KColorEditDoc::setErrorString(const QString& string) { + m_errorString = string; +} + +const QString& KColorEditDoc::errorString() const { + return m_errorString; +} + +PaletteHistory* KColorEditDoc::paletteHistory() { + return &m_paletteHistory; +} + +void KColorEditDoc::setPaletteCursorPos(const int pos) { + m_paletteCursorPos = pos; + + emit paletteAvailable( pos < m_palette.length() ); +} + +int KColorEditDoc::paletteCursorPos() { + return m_paletteCursorPos; +} + +void KColorEditDoc::setPaletteSelection(const int begin, const int end) { + m_paletteSelectionBegin = begin; + m_paletteSelectionEnd = end; + + emit selectionChanged( begin, end ); +} + +int KColorEditDoc::paletteSelectionBegin() const { + return m_paletteSelectionBegin; +} + +int KColorEditDoc::paletteSelectionEnd() const { + return m_paletteSelectionEnd; +} + +void KColorEditDoc::copyToClipboard(Palette& palette) { + QString text; + QTextOStream stream(&text); + palette.save(stream, 0, false); + KApplication::clipboard()->setText(text); + + emit clipboardChanged(); +} + +void KColorEditDoc::copy() { + Palette paletteCopy = m_palette.copy(paletteSelectionBegin(), + paletteSelectionEnd() - paletteSelectionBegin()); + copyToClipboard(paletteCopy); +} + +void KColorEditDoc::cut() { + Palette paletteCut = m_paletteHistory.cut(paletteSelectionBegin(), + paletteSelectionEnd() - paletteSelectionBegin()); + copyToClipboard(paletteCut); + setPaletteCursorPos(paletteSelectionBegin()); + setPaletteSelection(0, 0); + setModified(true); + slotRedrawAllViews(0); +} + +void KColorEditDoc::paste() { + Palette palettePaste; + QString text; + QTextIStream stream(&text); + text = KApplication::clipboard()->text(); + if(palettePaste.load( stream, false )) { + m_paletteHistory.paste(paletteCursorPos(), palettePaste); + setPaletteSelection(paletteCursorPos(), paletteCursorPos() + + palettePaste.length()); + setModified(true); + slotRedrawAllViews(0); + } +} + +void KColorEditDoc::insert(int index, const Color& color) { + Palette paletteInsert; + Color* insertColor = new Color(color); + paletteInsert.append(insertColor); + m_paletteHistory.paste(index, paletteInsert); + setPaletteCursorPos( index ); + setPaletteSelection(0, 0); + setModified(true); + slotRedrawAllViews(0); +} + +void KColorEditDoc::replace(int index, const Color& color) { + Palette paletteReplace; + Color* replaceColor = new Color(color); + paletteReplace.append(replaceColor); + m_paletteHistory.replace(index, paletteReplace); + setPaletteSelection(0, 0); + setModified(true); + slotRedrawAllViews(0); +} +#include "kcoloreditdoc.moc" diff --git a/kcoloredit/kcoloreditdoc.h b/kcoloredit/kcoloreditdoc.h new file mode 100644 index 00000000..1d209f46 --- /dev/null +++ b/kcoloredit/kcoloreditdoc.h @@ -0,0 +1,156 @@ +/*************************************************************************** + kcoloreditdoc.h - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef KCOLOREDITDOC_H +#define KCOLOREDITDOC_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +// include files for QT +#include <qobject.h> +#include <qstring.h> +#include <qptrlist.h> + +// application specific includes +#include "palette.h" +#include "palettehistory.h" + +// forward declaration of the KColorEdit classes +class KColorEditView; + +/** KColorEditDoc provides a document object for a document-view model. + * + * The KColorEditDoc class provides a document object that can be used in conjunction with the classes KColorEditApp and KColorEditView + * to create a document-view model for standard KDE applications based on KApplication and KMainWindow. Thereby, the document object + * is created by the KColorEditApp instance and contains the document structure with the according methods for manipulation of the document + * data by KColorEditView objects. Also, KColorEditDoc contains the methods for serialization of the document data from and to files. + * + * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team. + * @version KDevelop version 0.4 code generation + */ +class KColorEditDoc : public QObject +{ + Q_OBJECT + + public: + /** Constructor for the fileclass of the application */ + KColorEditDoc(QWidget *parent, const char *name=0); + /** Destructor for the fileclass of the application */ + ~KColorEditDoc(); + + /** adds a view to the document which represents the document contents. Usually this is your main view. */ + void addView(KColorEditView *view); + /** removes a view from the list of currently connected views */ + void removeView(KColorEditView *view); + /** sets the modified flag for the document after a modifying action on the view connected to the document.*/ + void setModified(bool modified); + /** returns if the document is modified or not. Use this to determine if your document needs saving by the user on closing.*/ + bool isModified() const { return m_modified; }; + /** "save modified" - asks the user for saving if the document is modified */ + bool saveModified(); + /** deletes the document's contents */ + void deleteContents(); + /** initializes the document generally */ + bool newDocument(); + /** closes the actual document */ + void closeDocument(); + /** loads the document */ + bool openDocument(const QString& filename); + /** saves the document */ + bool saveDocument(const QString& filename); + /** sets the path to the file connected with the document */ + void setAbsFilePath(const QString &filename); + /** returns the pathname of the current document file*/ + const QString& absFilePath() const; + /** sets the filename of the document */ + void setTitle(const QString &_t); + /** returns the title of the document */ + const QString& title() const; + /** @return a description of a possible unsuccessfull IO operation */ + const QString& errorString() const; + /** returns a pointer to paletteHistory */ + PaletteHistory* paletteHistory(); + /** sets a palette cursor position */ + void setPaletteCursorPos(const int pos); + /** @return a palette cursor position */ + int paletteCursorPos(); + /** Sets palette selection and enables or disables cut/paste + * depending on whether any colors are selected + */ + void setPaletteSelection(const int begin, const int end); + /** Gets lesser selection position or equal selection position + * if no colors are selected + */ + int paletteSelectionBegin() const; + /** Gets greater selection position or equal selection position + * if no colors are selected + */ + int paletteSelectionEnd() const; + /** Copies a selection into a clipboard */ + void copy(); + /** Cuts a selection into a clipboard */ + void cut(); + /** Pastes a selection from a clipboard */ + void paste(); + /** Inserts a color at index */ + void insert(int index, const Color& color); + /** Replaces a color at index */ + void replace(int index, const Color& color); + + protected: + /** Sets an error string if an IO operation was unsuccesfull */ + void setErrorString(const QString& string); + /** Copies a palette to clipboard */ + void copyToClipboard(Palette& palette); + + public slots: + /** Calls redraw() on all views connected to the document object, + * except for sender if sender is not null + */ + void slotRedrawAllViews(KColorEditView* sender, bool newDocument = false); + /** Sets a view mode */ + void slotChangeViewMode(bool viewColorNames); + + signals: + + void selectionChanged( int, int ); + void clipboardChanged(); + void modified( bool ); + void paletteAvailable( bool ); + + public: + /** the list of the views currently connected to the document */ + QPtrList<KColorEditView> *m_pViewList; + + private: + /** the modified flag of the current document */ + bool m_modified; + QString m_title; + QString m_absFilePath; + QString m_errorString; + + protected: + Palette m_palette; + PaletteHistory m_paletteHistory; + int m_paletteCursorPos; + int m_paletteSelectionBegin; + int m_paletteSelectionEnd; +}; + +#endif // KCOLOREDITDOC_H diff --git a/kcoloredit/kcoloreditui.rc b/kcoloredit/kcoloreditui.rc new file mode 100644 index 00000000..d2820c12 --- /dev/null +++ b/kcoloredit/kcoloreditui.rc @@ -0,0 +1,26 @@ +<!DOCTYPE kpartgui> +<kpartgui version="2" name="kcoloredit"> +<ActionProperties> + <Action name="color_from_palette" icon="colorize"/> + <Action name="color_from_screen" icon="colorpicker"/> +</ActionProperties> + +<MenuBar> + <Menu name="file"><text>&File</text> + <Action name="file_new_window" append="new_merge"/> + </Menu> + <Menu name="color"><text>&Color</text> + <Action name="color_from_palette"/> + <Action name="color_from_screen"/> + </Menu> + <Menu name="settings"> + <Action name="color_view_names" append="show_merge"/> + </Menu> +</MenuBar> +<ToolBar name="mainToolBar" noMerge="1"><text>Main Toolbar</text> + <Action name="file_new" /> + <Action name="file_open" /> + <Action name="file_save" /> + <Action name="color_from_screen"/> +</ToolBar> +</kpartgui> diff --git a/kcoloredit/kcoloreditview.cpp b/kcoloredit/kcoloreditview.cpp new file mode 100644 index 00000000..fe22f136 --- /dev/null +++ b/kcoloredit/kcoloreditview.cpp @@ -0,0 +1,282 @@ +/*************************************************************************** + kcoloreditview.cpp - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// include files for Qt +#include <qpainter.h> +#include <qlayout.h> +#include <qpushbutton.h> +#include <qvgroupbox.h> +#include <qlineedit.h> +#include <qcolor.h> +#include <qprinter.h> + +// include files for KDE +#include <kseparator.h> +#include <klocale.h> + +// application specific includes +#include "main.h" +#include "kcoloreditview.h" +#include "kcoloreditdoc.h" +#include "kcoloredit.h" +#include "palette.h" + +KColorEditView::KColorEditView(QWidget *parent, const char *name) : QSplitter(parent, name) { + colorSelector = new ColorSelector(this); + colorSelector->slotSetColor( + Color( RGB_MAX_COMPONENT_VALUE, RGB_MAX_COMPONENT_VALUE, RGB_MAX_COMPONENT_VALUE, "" )); + QWidget* paletteViewArea = new QWidget(this); + QVBoxLayout* paletteLayout = new QVBoxLayout(paletteViewArea); + paletteView = new PaletteView(16, 16, 2, this, paletteViewArea); + paletteLayout->addWidget(paletteView, 10); + QHBoxLayout* layout = new QHBoxLayout(); + QVBoxLayout* addColorLayout = new QVBoxLayout(4); + addColorLayout->setMargin(8); + QHBoxLayout* buttonsLayout = new QHBoxLayout(4); + QPushButton* addColorButton = new QPushButton(i18n( "Add Color" ), paletteViewArea); + connect(addColorButton, SIGNAL( clicked() ), SLOT( slotAddColor() )); + buttonsLayout->addWidget(addColorButton); + buttonsLayout->addStretch(10); + addColorLayout->addLayout(buttonsLayout); + QCheckBox* atCursorCheckBox = new QCheckBox(i18n( "At cursor" ), paletteViewArea); + connect(atCursorCheckBox, SIGNAL( toggled(bool) ), SLOT( slotAddColorAtCursor(bool) )); + addColorLayout->addWidget(atCursorCheckBox); + overwriteCheckBox = new QCheckBox(i18n( "Overwrite" ), paletteViewArea); + connect(overwriteCheckBox, SIGNAL( toggled(bool) ), SLOT( slotAddColorOverwrite(bool) )); + slotAddColorAtCursor(false); + slotAddColorOverwrite(false); + addColorLayout->addWidget(overwriteCheckBox); + addColorLayout->addStretch(10); + //KSeparator* hLine = new KSeparator(KSeparator::HLine, paletteViewArea); + //addColorLayout->addWidget(hLine); + //addColorLayout->addStretch(10); + //QCheckBox* cursorFollowsChosenColor = new QCheckBox(i18n( "Cursor follows" ), paletteViewArea); + //addColorLayout->addWidget(cursorFollowsChosenColor); + //connect(cursorFollowsChosenColor, SIGNAL( toggled(bool) ), + // paletteView, SLOT( slotCursorFollowsChosenColor(bool) )); + //cursorFollowsChosenColor->toggle(); + paletteView->slotCursorFollowsChosenColor(true); + layout->addLayout(addColorLayout, 0); + QVGroupBox* colorAtCursorFrame = new QVGroupBox(i18n("Color at Cursor"), paletteViewArea); + QWidget* colorAtCursorFrameArea = new QWidget(colorAtCursorFrame); + QVBoxLayout* colorAtCursorLayout = new QVBoxLayout(colorAtCursorFrameArea, 4); + QHBoxLayout* colorNameLayout = new QHBoxLayout(0); + QLabel* nameLabel = new QLabel(i18n( "Name" ) + ": ", colorAtCursorFrameArea); + colorNameLayout->addWidget(nameLabel, 0); + colorName = new QLineEdit(colorAtCursorFrameArea); + connect(colorName, SIGNAL( textChanged(const QString&) ), SLOT( slotSetColorName(const QString&) )); + colorNameLayout->addWidget(colorName, 10); + colorAtCursorLayout->addLayout(colorNameLayout); + QGridLayout* colorAtCursorComponentsLayout = new QGridLayout(3, 6, 4); + colorAtCursorLayout->addLayout(colorAtCursorComponentsLayout); + colorAtCursorComponentsLayout->setColStretch(1, 10); + colorAtCursorComponentsLayout->addColSpacing(2, 8); + colorAtCursorComponentsLayout->setColStretch(4, 10); + colorAtCursorComponentsLayout->setColStretch(5, 10); + QLabel* hLabel = new QLabel("H: ", colorAtCursorFrameArea); + colorAtCursorComponentsLayout->addWidget(hLabel, 0, 0); + colorAtCursorHValueLabel = new QLabel("", colorAtCursorFrameArea); + setColorAtCursorComponentValueLabelSizes(colorAtCursorHValueLabel); + colorAtCursorComponentsLayout->addWidget(colorAtCursorHValueLabel, 0, 1); + QLabel* sLabel = new QLabel("S: ", colorAtCursorFrameArea); + colorAtCursorComponentsLayout->addWidget(sLabel, 1, 0); + colorAtCursorSValueLabel = new QLabel("", colorAtCursorFrameArea); + setColorAtCursorComponentValueLabelSizes(colorAtCursorSValueLabel); + colorAtCursorComponentsLayout->addWidget(colorAtCursorSValueLabel, 1, 1); + QLabel* vLabel = new QLabel("V: ", colorAtCursorFrameArea); + colorAtCursorComponentsLayout->addWidget(vLabel, 2, 0); + colorAtCursorVValueLabel = new QLabel("", colorAtCursorFrameArea); + setColorAtCursorComponentValueLabelSizes(colorAtCursorVValueLabel); + colorAtCursorComponentsLayout->addWidget(colorAtCursorVValueLabel, 2, 1); + QLabel* rLabel = new QLabel("R: ", colorAtCursorFrameArea); + colorAtCursorComponentsLayout->addWidget(rLabel, 0, 3); + colorAtCursorRValueLabel = new QLabel("", colorAtCursorFrameArea); + setColorAtCursorComponentValueLabelSizes(colorAtCursorRValueLabel); + colorAtCursorComponentsLayout->addWidget(colorAtCursorRValueLabel, 0, 4); + QLabel* gLabel = new QLabel("G: ", colorAtCursorFrameArea); + colorAtCursorComponentsLayout->addWidget(gLabel, 1, 3); + colorAtCursorGValueLabel = new QLabel("", colorAtCursorFrameArea); + setColorAtCursorComponentValueLabelSizes(colorAtCursorGValueLabel); + colorAtCursorComponentsLayout->addWidget(colorAtCursorGValueLabel, 1, 4); + QLabel* bLabel = new QLabel("B: ", colorAtCursorFrameArea); + colorAtCursorComponentsLayout->addWidget(bLabel, 2, 3); + colorAtCursorBValueLabel = new QLabel("", colorAtCursorFrameArea); + setColorAtCursorComponentValueLabelSizes(colorAtCursorBValueLabel); + colorAtCursorComponentsLayout->addWidget(colorAtCursorBValueLabel, 2, 4); + QHBoxLayout* colorAtCursorRgbStringLayout = new QHBoxLayout(); + QLabel* colorAtCursorRgbStringLabel = + new QLabel("RGB " + i18n( "hex." ) + ": ", colorAtCursorFrameArea); + colorAtCursorRgbStringLayout->addWidget(colorAtCursorRgbStringLabel); + colorAtCursorRgbStringValueLabel = new QLabel("", colorAtCursorFrameArea); + colorAtCursorRgbStringValueLabel->setFixedWidth( + colorAtCursorRgbStringValueLabel->fontMetrics().width( QString("8888888") )); + colorAtCursorRgbStringLayout->addWidget(colorAtCursorRgbStringValueLabel); + colorAtCursorRgbStringLayout->addStretch(); + colorAtCursorLayout->addLayout(colorAtCursorRgbStringLayout); + layout->addWidget(colorAtCursorFrame, 10); + layout->addSpacing(8); + paletteLayout->addSpacing(4); + paletteLayout->addLayout(layout); + paletteLayout->addSpacing(4); + inColorNameChanging = false; + doNotUpdateColorLabels = false; +} + +KColorEditView::~KColorEditView() { +} + +void KColorEditView::setColorAtCursorComponentValueLabelSizes(QLabel* const label) { + label->setMinimumWidth(label->fontMetrics().width( QString("888") )); + label->setMaximumWidth(label->fontMetrics().width( QString("88888") )); +} + +KColorEditDoc *KColorEditView::document() const { + KColorEditApp *theApp=(KColorEditApp *) parentWidget(); + + return theApp->document(); +} + +void KColorEditView::print(QPrinter *pPrinter) { + QPainter printpainter; + printpainter.begin(pPrinter); + + // TODO: add your printing code here + + printpainter.end(); +} + +void KColorEditView::chooseColor(Color* const color) { + colorSelector->slotSetColor(color); +} + +void KColorEditView::slotCursorPosChanged(int position) { + Palette* palette = document()->paletteHistory()->editableStream(); + if(position < palette->length()) { + Color* color = palette->color(position); + QString string; + inColorNameChanging = true; + colorName->setText(color->name()); + colorName->setEnabled(true); + inColorNameChanging = false; + int rComponent = color->component(Color::RED_INDEX); + int gComponent = color->component(Color::GREEN_INDEX); + int bComponent = color->component(Color::BLUE_INDEX); + colorAtCursorRValueLabel->setText(string.setNum( rComponent )); + colorAtCursorGValueLabel->setText(string.setNum( gComponent )); + colorAtCursorBValueLabel->setText(string.setNum( bComponent )); + QColor hsvColor(rComponent, gComponent, bComponent); + int hComponent; + int sComponent; + int vComponent; + hsvColor.hsv(&hComponent, &sComponent, &vComponent); + colorAtCursorHValueLabel->setText(string.setNum( hComponent )); + colorAtCursorSValueLabel->setText(string.setNum( sComponent )); + colorAtCursorVValueLabel->setText(string.setNum( vComponent )); + colorAtCursorRgbStringValueLabel->setText(string.sprintf( "%02x%02x%02x", + rComponent, gComponent, bComponent )); + } else { + colorName->setText(""); + colorName->setEnabled(false); + colorAtCursorHValueLabel->setText(""); + colorAtCursorSValueLabel->setText(""); + colorAtCursorVValueLabel->setText(""); + colorAtCursorRValueLabel->setText(""); + colorAtCursorGValueLabel->setText(""); + colorAtCursorBValueLabel->setText(""); + colorAtCursorRgbStringValueLabel->setText(""); + } +} + +void KColorEditView::slotViewColorNames(bool viewColorNames) { + paletteView->slotViewColorNames(viewColorNames); +} + +void KColorEditView::updateColorValueLabels() { + if(!doNotUpdateColorLabels) + slotCursorPosChanged(document()->paletteCursorPos()); +} + +void KColorEditView::redraw(bool newDocument) { + if(newDocument) + paletteView->setScrollBarValue(0); + paletteView->redraw(); + updateColorValueLabels(); +} + +void KColorEditView::slotAddColor() { + Color color = colorSelector->color(); + Palette* palette = document()->paletteHistory()->editableStream(); + color.setName(""); + int index; + if(addColorAtCursor) + index = document()->paletteCursorPos(); + else + index = palette->length(); + switch(addColorMode) + { + case INSERT_COLOR: + document()->insert(index, color); + break; + + case REPLACE_COLOR: + if(index < palette->length()) + document()->replace(index, color); + else + document()->insert(index, color); + break; + + } +} + +void KColorEditView::slotAddColorAtCursor(bool atCursor) { + addColorAtCursor = atCursor; + overwriteCheckBox->setEnabled(addColorAtCursor); +} + +void KColorEditView::slotAddColorOverwrite(bool overwrite) { + if(overwrite) + addColorMode = REPLACE_COLOR; + else + addColorMode = INSERT_COLOR; +} + +void KColorEditView::slotSetColorName(const QString& name) { + if(!inColorNameChanging) { + /* + Palette* palette = getDocument()->getPaletteHistory()->getEditableStream(); + int cursorPos = getDocument()->getPaletteCursorPos(); + if(cursorPos < palette->length()) { + palette->getColor(cursorPos)->setName(name); + getDocument()->setModified(true); + getDocument()->slotRedrawAllViews(this); + } + */ + Palette* palette = document()->paletteHistory()->editableStream(); + int cursorPos = document()->paletteCursorPos(); + if(cursorPos < palette->length()) { + Color newColor( + palette->color(cursorPos)->component(Color::RED_INDEX), + palette->color(cursorPos)->component(Color::GREEN_INDEX), + palette->color(cursorPos)->component(Color::BLUE_INDEX), + name); + doNotUpdateColorLabels = true; + document()->replace(cursorPos, newColor); + doNotUpdateColorLabels = false; + } + } +} +#include "kcoloreditview.moc" diff --git a/kcoloredit/kcoloreditview.h b/kcoloredit/kcoloreditview.h new file mode 100644 index 00000000..ec0ca17f --- /dev/null +++ b/kcoloredit/kcoloreditview.h @@ -0,0 +1,128 @@ +/*************************************************************************** + kcoloreditview.h - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef KCOLOREDITVIEW_H +#define KCOLOREDITVIEW_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +// include files for Qt +#include <qsplitter.h> +#include <qcheckbox.h> +#include <qlabel.h> + +// application specific includes +#include "colorselector.h" +#include "paletteview.h" + +class KColorEditDoc; + +/** The KColorEditView class provides the view widget for the KColorEditApp instance. + * The View instance inherits QWidget as a base class and represents the view object of a KMainWindow. As KColorEditView is part of the + * docuement-view model, it needs a reference to the document object connected with it by the KColorEditApp class to manipulate and display + * the document structure provided by the KColorEditDoc class. + * + * @author Source Framework Automatically Generated by KDevelop, (c) The KDevelop Team. + * @version KDevelop version 0.4 code generation + */ +class KColorEditView : public QSplitter { + Q_OBJECT + + public: + /** Constructor for the main view */ + KColorEditView(QWidget *parent = 0, const char *name = 0); + /** Destructor for the main view */ + ~KColorEditView(); + + /** returns a pointer to the document connected to the view instance. Mind that this method requires a KColorEditApp instance as a parent + * widget to get to the window document pointer by calling the KColorEditApp::getDocument() method. + * + * @see KColorEditApp#getDocument + */ + KColorEditDoc *document() const; + + /** Contains the implementation for printing functionality */ + void print(QPrinter *pPrinter); + /** Chooses a color to the color selector */ + void chooseColor(Color* const color); + /** Updates the view after the document has been changed */ + void redraw(bool newDocument); + + public slots: + /** Notifies that the cursor position changed */ + void slotCursorPosChanged(int position); + /** Whether to view color names */ + void slotViewColorNames(bool viewColorNames); + + protected: + ColorSelector* colorSelector; + PaletteView* paletteView; + + protected slots: + /** Adds a color from color selector at cursor position. It inserts or replaces a color, + * depending on addColorMode + */ + void slotAddColor(); + /** Sets if add a color at cursor */ + void slotAddColorAtCursor(bool atCursor); + /** Sets whether insert or replace a color */ + void slotAddColorOverwrite(bool overwrite); + /** Sets a color name */ + void slotSetColorName(const QString& name); + + protected: + /** Add color mode constants */ + enum { INSERT_COLOR = 0, + REPLACE_COLOR = 1 }; + + /** Color mode widget */ + QCheckBox* overwriteCheckBox; + /** Color name widget */ + QLineEdit* colorName; + /** H component value label of the color at cursor */ + QLabel* colorAtCursorHValueLabel; + /** S component value label of the color at cursor */ + QLabel* colorAtCursorSValueLabel; + /** V component value label of the color at cursor */ + QLabel* colorAtCursorVValueLabel; + /** R component value label of the color at cursor */ + QLabel* colorAtCursorRValueLabel; + /** G component value label of the color at cursor */ + QLabel* colorAtCursorGValueLabel; + /** B component value label of the color at cursor */ + QLabel* colorAtCursorBValueLabel; + /** RGB Hex string value label of the color at cursor */ + QLabel* colorAtCursorRgbStringValueLabel; + /** If add a color at cursor */ + bool addColorAtCursor; + /** Add color mode */ + int addColorMode; + /** If in color name changing */ + bool inColorNameChanging; + /** Whether not to update color labels */ + bool doNotUpdateColorLabels; + + protected: + /** Sets component value label of the color at cursor sizes */ + void setColorAtCursorComponentValueLabelSizes(QLabel* const label); + /** Updates color value labels */ + void updateColorValueLabels(); +}; + +#endif // KCOLOREDITVIEW_H diff --git a/kcoloredit/kxycolorselector.cpp b/kcoloredit/kxycolorselector.cpp new file mode 100644 index 00000000..e12f7987 --- /dev/null +++ b/kcoloredit/kxycolorselector.cpp @@ -0,0 +1,186 @@ +/*************************************************************************** + kxycolorselector.cpp - description + ------------------- + begin : Fri Jul 7 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <qpainter.h> +#include <qpixmap.h> +#include <qimage.h> +#include <kimageeffect.h> +#include <kpalette.h> + +#include "kxycolorselector.h" + +KXYColorSelector::KXYColorSelector(QWidget *parent, const char *name) : KXYSelector(parent,name) { + setBackgroundMode(NoBackground); + setRange(0, 0, COMPONENT_SELECTION_RESOLUTION - 1, COMPONENT_SELECTION_RESOLUTION - 1); + setType(TYPE_NONE); + setGlobalComponent(0); + setMinimumSize(RGB_MAX_COMPONENT_VALUE/2 + 4, RGB_MAX_COMPONENT_VALUE/2 + 4); + setMaximumSize(512, 512); + updateContents(); +} +KXYColorSelector::~KXYColorSelector() { + +} + +void KXYColorSelector::setType(const int type) { + this->type = type; +} + +void KXYColorSelector::updateContents() { + drawPalette(&pixmap); + repaint(); +} + +void KXYColorSelector::resizeEvent(QResizeEvent*) { + setValues(xValue(), yValue()); + updateContents(); +} + +void KXYColorSelector::drawContents(QPainter* painter) { + painter->drawPixmap(contentsRect().x(), contentsRect().y(), pixmap); +} + +void KXYColorSelector::drawCursor(QPainter* painter, int x, int y) { + QColor color; + int colorX = x - contentsRect().x(); + int colorY = y - contentsRect().y(); + if(colorX < 0) + colorX = 0; + if(colorY < 0) + colorY = 0; + if(colorX > contentsRect().width() - 1) + colorX = contentsRect().width() - 1; + if(colorY > contentsRect().height() - 1) + colorY = contentsRect().height() - 1; + setColor(&color, colorX, colorY); + QColor cursorColor; + if(( 2*color.red() + 4*color.green() + 1*color.blue() )*1.0/ + ( 2*255 + 4*255 + 1*255 ) > 0.65) + cursorColor = Qt::black; + else + cursorColor = Qt::white; + painter->setPen(QPen( cursorColor )); + const int lineBegin = 2; + const int lineEnd = 6; + painter->drawLine(x + lineBegin, y - lineBegin, x + lineEnd, y - lineEnd); + painter->drawLine(x + lineBegin, y + lineBegin, x + lineEnd, y + lineEnd); + painter->drawLine(x - lineBegin, y + lineBegin, x - lineEnd, y + lineEnd); + painter->drawLine(x - lineBegin, y - lineBegin, x - lineEnd, y - lineEnd); +} + +void KXYColorSelector::setGlobalComponent(const int component) { + m_globalComponent = component; +} + +int KXYColorSelector::globalComponent() const{ + return m_globalComponent; +} + +void KXYColorSelector::setColor(QColor* const color, const int x, const int y) { + int xSize = contentsRect().width(); + int ySize = contentsRect().height(); + switch(type) { + case TYPE_HS: + color->setHsv(360*x/xSize, 256*( ySize - 1 - y )/ySize, + globalComponent()); + break; + + case TYPE_VS: + color->setHsv(globalComponent(), 256*( ySize - 1 - y )/ySize, + 256*x/xSize); + break; + + case TYPE_HV: + color->setHsv(360*x/xSize, globalComponent(), + 256*( ySize - 1 - y )/ySize); + break; + + case TYPE_RG: + color->setRgb(x/xSize, 256*( ySize - 1 - y )/ySize, + globalComponent()); + break; + + case TYPE_GB: + color->setRgb(globalComponent(), 256*x/xSize, + 256*( ySize - 1 - y )/ySize); + break; + + case TYPE_BR: + color->setRgb(256*( ySize - 1 - y )/ySize, globalComponent(), + 256*x/xSize); + break; + + case TYPE_NONE: + color->setRgb(192, 192, 192); + break; + + } +} + +QColor* KXYColorSelector::standardColorsPalette() { + QColor* palette = new QColor[STANDARD_PALETTE_SIZE]; + int i = 0; + palette[i++] = Qt::red; + palette[i++] = Qt::green; + palette[i++] = Qt::blue; + palette[i++] = Qt::cyan; + palette[i++] = Qt::magenta; + palette[i++] = Qt::yellow; + palette[i++] = Qt::darkRed; + palette[i++] = Qt::darkGreen; + palette[i++] = Qt::darkBlue; + palette[i++] = Qt::darkCyan; + palette[i++] = Qt::darkMagenta; + palette[i++] = Qt::darkYellow; + palette[i++] = Qt::white; + palette[i++] = Qt::lightGray; + palette[i++] = Qt::gray; + palette[i++] = Qt::darkGray; + palette[i++] = Qt::black; + return palette; +} + +void KXYColorSelector::drawPalette(QPixmap* pixmap) { + int xSize = contentsRect().width(); + int ySize = contentsRect().height(); + QImage image(xSize, ySize, 32); + QColor color; + int x; + int y; + + if(type != TYPE_NONE) { + for (y = 0; y < ySize; ++y) + { + unsigned int* p = (unsigned int*)image.scanLine(y); + for(x = 0; x < xSize; ++x) + { + setColor(&color, x, y); + *p = color.rgb(); + ++p; + } + } + if (QColor::numBitPlanes() <= 8) + { + QColor* standardPalette = standardColorsPalette(); + KImageEffect::dither(image, standardPalette, STANDARD_PALETTE_SIZE); + delete[] standardPalette; + } + } + pixmap->convertFromImage(image); +} + +#include "kxycolorselector.moc" diff --git a/kcoloredit/kxycolorselector.h b/kcoloredit/kxycolorselector.h new file mode 100644 index 00000000..3213c59c --- /dev/null +++ b/kcoloredit/kxycolorselector.h @@ -0,0 +1,97 @@ +/*************************************************************************** + kxycolorselector.h - description + ------------------- + begin : Fri Jul 7 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef KXYCOLORSELECTOR_H +#define KXYCOLORSELECTOR_H + +#include <qwidget.h> +#include <kselect.h> + +#include "main.h" + +/** A widget for selecting two of color components + * @author Artur Rataj + */ +class KXYColorSelector : public KXYSelector { + Q_OBJECT + +public: + /** The types of the selector. They specify a color component subset */ + enum { TYPE_NONE = 0, + TYPE_HS = 1, + TYPE_VS = 2, + TYPE_HV = 3, + TYPE_RG = 4, + TYPE_GB = 5, + TYPE_BR = 6, + TYPE_ = 7, + /** Component selection resolution */ + COMPONENT_SELECTION_RESOLUTION = 10000 }; + +public: + /** Constructs a two-dimensional color component selector widget, + * with a type TYPE_NONE and ranges 0 .. MAX_COLOR_COMPONENT_VALUE + */ + KXYColorSelector(QWidget *parent=0, const char *name=0); + ~KXYColorSelector(); + /** Set the type of the selector */ + void setType(const int type); + /** Update the pixmap */ + void updateContents(); + /** Set the global component */ + void setGlobalComponent(const int component); + /** @return The global component */ + int globalComponent() const; + +protected: + /** The number of colors that are used to dither the pixmap + * if number of color planes <= 8. The palette returned by + * getStandardColorsPalette() is of the size. + */ + enum { STANDARD_PALETTE_SIZE = 17 }; + + /** A type of the selector */ + int type; + /** The global component value */ + int m_globalComponent; + + /** Draws the contents of the widget on a pixmap, + * which is used for buffering. + */ + virtual void drawPalette( QPixmap *pixmap ); + /** @reimplemented */ + virtual void resizeEvent( QResizeEvent * ); + /** Reimplemented from KXYSelector. This drawing is + * buffered in a pixmap here. As real drawing + * routine, drawPalette() is used. + */ + virtual void drawContents( QPainter *painter ); + /** Draws the cursor */ + virtual void drawCursor(QPainter* painter, int x, int y); + /** set a color at a given coordinate */ + virtual void setColor(QColor* const color, const int x, const int y); + /** @return STANDARD_PALETTE_SIZE colors used to dither the + * pixmap if number of color planes <= 8 + */ + QColor* standardColorsPalette(); + +private: + /* The buffering pixmap */ + QPixmap pixmap; +}; + +#endif diff --git a/kcoloredit/kzcolorselector.cpp b/kcoloredit/kzcolorselector.cpp new file mode 100644 index 00000000..36953180 --- /dev/null +++ b/kcoloredit/kzcolorselector.cpp @@ -0,0 +1,170 @@ +/*************************************************************************** + kzcolorselector.cpp - description + ------------------- + begin : Fri Jul 14 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <qpainter.h> +#include <qimage.h> +#include <kimageeffect.h> +#include <kpalette.h> + +#include "main.h" +#include "kzcolorselector.h" + +KZColorSelector::KZColorSelector(Orientation o, QWidget *parent, const char *name) : + KSelector(o, parent, name) { + baseColorH = -1; + baseColorS = 0; + baseColorV = 0; + pixmap.setOptimization( QPixmap::BestOptim ); +} +KZColorSelector::~KZColorSelector() { +} + +void KZColorSelector::setType(const int type) { + this->type = type; + switch(this->type) { + case TYPE_H: + setRange(0, HSV_MAX_H_VALUE); + break; + + case TYPE_S: + setRange(0, HSV_MAX_S_VALUE); + break; + + case TYPE_V: + setRange(0, HSV_MAX_V_VALUE); + break; + + } +} + +void KZColorSelector::updateContents() { + drawPalette(&pixmap); + repaint(false); +} + +void KZColorSelector::resizeEvent(QResizeEvent*) { + updateContents(); +} + +void KZColorSelector::drawContents(QPainter* painter) { + painter->drawPixmap(contentsRect().x(), contentsRect().y(), pixmap); +} + +void KZColorSelector::setBaseColor(const QColor& color) { + color.hsv(&baseColorH, &baseColorS, &baseColorV); +} + +void KZColorSelector::setBaseColorHsv(const int colorH, + const int colorS, const int colorV) { + baseColorH = colorH; + baseColorS = colorS; + baseColorV = colorV; +} + +void KZColorSelector::updatePointerPos() { + int pos; + switch(type) { + case TYPE_H: + pos = baseColorH; + if(pos < 0) + pos = 0; + break; + + case TYPE_S: + pos = baseColorS; + break; + + case TYPE_V: + pos = baseColorV; + break; + + default: + pos = 0; + break; + + } + setValue(pos); +} + +void KZColorSelector::setColor(QColor* const color, const int y) { + int ySize = contentsRect().height(); + switch(type) { + case TYPE_H: + color->setHsv(( ySize - 1 - y )*360/ySize, baseColorS, baseColorV); + break; + + case TYPE_S: + color->setHsv(baseColorH, ( ySize - 1 - y )*256/ySize, baseColorV); + break; + + case TYPE_V: + color->setHsv(baseColorH, baseColorS, ( ySize - 1 - y )*256/ySize); + break; + + } +} + +QColor* KZColorSelector::getStandardColorsPalette() { + QColor* palette = new QColor[( int )STANDARD_PALETTE_SIZE]; + int i = 0; + palette[i++] = Qt::red; + palette[i++] = Qt::green; + palette[i++] = Qt::blue; + palette[i++] = Qt::cyan; + palette[i++] = Qt::magenta; + palette[i++] = Qt::yellow; + palette[i++] = Qt::darkRed; + palette[i++] = Qt::darkGreen; + palette[i++] = Qt::darkBlue; + palette[i++] = Qt::darkCyan; + palette[i++] = Qt::darkMagenta; + palette[i++] = Qt::darkYellow; + palette[i++] = Qt::white; + palette[i++] = Qt::lightGray; + palette[i++] = Qt::gray; + palette[i++] = Qt::darkGray; + palette[i++] = Qt::black; + return palette; +} + +void KZColorSelector::drawPalette(QPixmap* pixmap) { + int xSize = contentsRect().width(); + int ySize = contentsRect().height(); + QImage image(xSize, ySize, 32); + QColor color; + int x; + int y; + + for (y = 0; y < ySize; ++y) + { + unsigned int* p = (unsigned int*)image.scanLine(y); + for(x = 0; x < xSize; ++x) + { + setColor(&color, y); + *p = color.rgb(); + ++p; + } + } + if (QColor::numBitPlanes() <= 8) + { + QColor* standardPalette = getStandardColorsPalette(); + KImageEffect::dither(image, standardPalette, STANDARD_PALETTE_SIZE); + delete[] standardPalette; + } + pixmap->convertFromImage(image); +} +#include "kzcolorselector.moc" diff --git a/kcoloredit/kzcolorselector.h b/kcoloredit/kzcolorselector.h new file mode 100644 index 00000000..cafdb254 --- /dev/null +++ b/kcoloredit/kzcolorselector.h @@ -0,0 +1,89 @@ +/*************************************************************************** + kzcolorselector.h - description + ------------------- + begin : Fri Jul 14 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef KZCOLORSELECTOR_H +#define KZCOLORSELECTOR_H + +#include "qcolor.h" +#include "qpixmap.h" +#include "kselect.h" + +#include "color.h" + +/** A widget for selecting a color component + * @author Artur Rataj + */ +class KZColorSelector : public KSelector { + Q_OBJECT + +public: + /** Selector type constants */ + enum { TYPE_H = 0, + TYPE_S = 1, + TYPE_V = 2 }; + + /** Constructs the widget */ + KZColorSelector(Orientation o, QWidget *parent=0, const char *name=0); + ~KZColorSelector(); + /** Sets the selector type */ + void setType(const int type); + /** Update the pixmap */ + void updateContents(); + /** Set the global components */ + void setBaseColor(const QColor& color); + /** Set the global components using HSV components */ + void setBaseColorHsv(const int colorH, const int colorS, const int colorV); + /** Updates a pointer position due to the base color */ + void updatePointerPos(); + +protected: + /** The number of colors that are used to dither the pixmap + * if number of color planes <= 8. The palette returned by + * getStandardColorsPalette() is of the size. + */ + enum { STANDARD_PALETTE_SIZE = 17 }; + + /** A type of the selector */ + int type; + /** A base color H component */ + int baseColorH; + /** A base color S component */ + int baseColorS; + /** A base color V component */ + int baseColorV; + + /** Draws the contents of the widget on a pixmap, + * which is used for buffering. + */ + virtual void drawPalette( QPixmap *pixmap ); + /** @reimplemented */ + virtual void resizeEvent( QResizeEvent * ); + /** Draws a color gradient in the selector */ + virtual void drawContents( QPainter *painter ); + /** Sets a color at a given coordinate */ + virtual void setColor(QColor* const color, const int y); + /** @return STANDARD_PALETTE_SIZE colors used to dither the + * pixmap if number of color planes <= 8 + */ + QColor* getStandardColorsPalette(); + +private: + /* The buffering pixmap */ + QPixmap pixmap; +}; + +#endif diff --git a/kcoloredit/loadpalettedlg.cpp b/kcoloredit/loadpalettedlg.cpp new file mode 100644 index 00000000..b426a874 --- /dev/null +++ b/kcoloredit/loadpalettedlg.cpp @@ -0,0 +1,111 @@ +/*************************************************************************** + loadpalettedlg.cpp - description + ------------------- + begin : Sat Jul 8 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <string.h> + +#include <qlayout.h> +#include <qlabel.h> +#include <qstring.h> +#include <qstringlist.h> +#include <qpushbutton.h> +#include <klocale.h> +#include <kstandarddirs.h> +#include <kpalette.h> +#include <kfiledialog.h> + +#include "main.h" +#include "palette.h" +#include "loadpalettedlg.h" + +LoadPaletteDlg::LoadPaletteDlg(QWidget *parent, const char *name) + : KDialogBase(parent, name, true, i18n( "Load Palette" ), + Ok|Cancel, Ok, true) { + fileName = ""; + QWidget *mainWidget = new QWidget( this ); + setMainWidget( mainWidget ); + QVBoxLayout* topLayout = new QVBoxLayout(mainWidget, 0, spacingHint()); + QLabel* label = new QLabel(i18n( "Select a palette:" ), mainWidget); + topLayout->addWidget(label); + paletteBox = new QComboBox(false, mainWidget); + browseFileNameInserted = false; + QStringList palettesList = Palette::kdePalettes(); + for(QStringList::Iterator palette = palettesList.begin(); + palette != palettesList.end(); ++palette) { + bool prepend = (*palette).contains( "colors/Custom_Colors" ); + QString fileName = locate("config", (*palette)); + if(prepend) { + palettesFileNames.prepend(fileName); + setFileName(&fileName); + } else { + palettesFileNames.append(fileName); + if(palette == palettesList.begin()) + setFileName(&fileName); + } + QString paletteName = (*palette).mid(palettesDir.length() + 1); + if(paletteName == "Custom_Colors") + paletteName = i18n("Custom Colors"); + else if(paletteName == "Recent_Colors") + paletteName = i18n("Recent Colors"); + if(prepend) + paletteBox->insertItem(paletteName, 0); + else + paletteBox->insertItem(paletteName); + } + connect(paletteBox, SIGNAL( activated(int) ), SLOT( setFileName(int) )); + topLayout->addWidget(paletteBox); + QHBoxLayout* browseLayout = new QHBoxLayout( mainWidget ); + QPushButton* browseButton = new QPushButton(i18n( "Browse..." ), + mainWidget); + connect(browseButton, SIGNAL( clicked() ), SLOT( browseFileNames() )); + browseLayout->addWidget(browseButton); + browseLayout->addStretch(10); + topLayout->addLayout(browseLayout); + topLayout->addStretch(10); + resize(300, 155); +} +LoadPaletteDlg::~LoadPaletteDlg() { +} + +void LoadPaletteDlg::setFileName(QString* fileName) { + this->fileName = *fileName; +} + +void LoadPaletteDlg::setFileName(int index) { + setFileName(&palettesFileNames[index]); +} + +void LoadPaletteDlg::browseFileNames() { + QString fileToOpen = KFileDialog::getOpenFileName(lastOpenPaletteFileDir, + i18n("*|All Files"), this, i18n("Open File")); + if(!fileToOpen.isEmpty()) { + fileName = fileToOpen; + if(browseFileNameInserted) { + paletteBox->removeItem(0); + palettesFileNames.remove(palettesFileNames.begin()); + } + paletteBox->insertItem(fileName, 0); + paletteBox->setCurrentItem(0); + palettesFileNames.prepend(fileName); + browseFileNameInserted = true; + lastOpenPaletteFileDir = fileName; + } +} + +QString LoadPaletteDlg::getFileName() { + return fileName; +} +#include "loadpalettedlg.moc" diff --git a/kcoloredit/loadpalettedlg.h b/kcoloredit/loadpalettedlg.h new file mode 100644 index 00000000..3168ed68 --- /dev/null +++ b/kcoloredit/loadpalettedlg.h @@ -0,0 +1,67 @@ +/*************************************************************************** + loadpalettedlg.h - description + ------------------- + begin : Sat Jul 8 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef LOADPALETTEDLG_H +#define LOADPALETTEDLG_H + +#include <qcombobox.h> +#include <kdialog.h> + +/**A dialog showing a list of installed palettes, with a possibility + *of choosing a custom file + *@author Artur Rataj + */ +class LoadPaletteDlg : public KDialogBase { + Q_OBJECT + +public: + /** constructs the dialog + */ + LoadPaletteDlg(QWidget *parent = 0, const char *name = 0); + ~LoadPaletteDlg(); + /** @return the fetched file name + */ + QString getFileName(); + +protected slots: + /** sets fileName + */ + void setFileName(QString* fileName); + /** sets fileName to that at position index in palettesFileNames + */ + void setFileName(int index); + /** browses file names and if a file name fetched sets fileName + */ + void browseFileNames(); + +private: + /** A widget holding palettes names + */ + QComboBox* paletteBox; + /** A list of KDE palettes file names + */ + QStringList palettesFileNames; + /** A fetched palette file name + */ + QString fileName; + /** whether a browse file name hab already been inserted into + * palettesFilenames + */ + bool browseFileNameInserted; +}; + +#endif diff --git a/kcoloredit/main.cpp b/kcoloredit/main.cpp new file mode 100644 index 00000000..fcc2ac66 --- /dev/null +++ b/kcoloredit/main.cpp @@ -0,0 +1,74 @@ +/*************************************************************************** + main.cpp - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <kcmdlineargs.h> +#include <kaboutdata.h> +#include <klocale.h> +#include <kdebug.h> + +#include "kcoloredit.h" + +static const char description[] = + I18N_NOOP("KColorEdit"); +// INSERT A DESCRIPTION FOR YOUR APPLICATION HERE + + +static KCmdLineOptions options[] = +{ + { "+[File]", I18N_NOOP("File to open"), 0 }, + KCmdLineLastOption + // INSERT YOUR COMMANDLINE OPTIONS HERE +}; + +int main(int argc, char *argv[]) +{ + + KAboutData aboutData( "kcoloredit", I18N_NOOP("KColorEdit"), + VERSION, description, KAboutData::License_GPL, + "(c) 2000, Artur Rataj"); + aboutData.addAuthor("Artur Rataj",0, "[email protected]"); + aboutData.addCredit( "Nadeem Hasan", I18N_NOOP( "Rewrote UI code " + "to be KDE standards compliant" ), "[email protected]" ); + KCmdLineArgs::init( argc, argv, &aboutData ); + KCmdLineArgs::addCmdLineOptions( options ); // Add our own options. + + KApplication app; + + if (app.isRestored()) + { + RESTORE(KColorEditApp); + } + else + { + KColorEditApp *kcoloredit = new KColorEditApp(); + kcoloredit->show(); + + KCmdLineArgs *args = KCmdLineArgs::parsedArgs(); + + if (args->count()) + { + kcoloredit->openDocumentFile(args->arg(0)); + } + else + { + kcoloredit->openDocumentFile(); + } + args->clear(); + } + + return app.exec(); +} diff --git a/kcoloredit/main.h b/kcoloredit/main.h new file mode 100644 index 00000000..5e0b086a --- /dev/null +++ b/kcoloredit/main.h @@ -0,0 +1,52 @@ +/*************************************************************************** + main.h - description + ------------------- + begin : Sat Jul 8 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef __MAIN_H__ +#define __MAIN_H__ + +#include <qstring.h> +#include <qdir.h> + +/** The maximum red, green or blue component value in RGB scheme + */ +const int RGB_MAX_COMPONENT_VALUE = 255; + +/** The maximum hue in HSV scheme + */ +const int HSV_MAX_H_VALUE = 359; + +/** The maximum saturation in HSV scheme + */ +const int HSV_MAX_S_VALUE = 255; + +/** The maximum value in HSV scheme + */ +const int HSV_MAX_V_VALUE = 255; + +/** name of KDE config directories containing palette files + */ +static const QString palettesDir("colors"); + +/** last open file dialog path + */ +static QString lastOpenPaletteFileDir = QDir::homeDirPath(); + +/** last save file as dialog path + */ +static QString lastSavePaletteAsFileDir = QDir::homeDirPath(); + +#endif /* !defined( __MAIN_H__ ) */ diff --git a/kcoloredit/palette.cpp b/kcoloredit/palette.cpp new file mode 100644 index 00000000..1e11aa27 --- /dev/null +++ b/kcoloredit/palette.cpp @@ -0,0 +1,226 @@ +/*************************************************************************** + palette.cpp - description + ------------------- + begin : Sat Jul 8 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <qstring.h> +#include <qstringlist.h> +#include <qtextstream.h> +#include <qregexp.h> +#include <kglobal.h> +#include <kstandarddirs.h> +#include <klocale.h> + +#include "main.h" +#include "color.h" +#include "palette.h" + +Palette::Palette() { + init(); +} +Palette::Palette(const Palette& palette) { + init(); + for(int colorIndex = 0; colorIndex < palette.length(); ++colorIndex) { + Color* color = new Color(*( (Palette&)palette ).color( colorIndex )); + append(color); + } + setName(palette.name()); +} +Palette::~Palette() { +} + +void Palette::init() { + colors.setAutoDelete(true); +} + +QStringList Palette::kdePalettes() { + QStringList paletteList; + KGlobal::dirs()->findAllResources("config", palettesDir + "/*", false, true, paletteList); + return paletteList; +} + +void Palette::setName(const QString& name) { + m_name = name; +} + +const QString& Palette::name() const { + return m_name; +} + +void Palette::insert(const int index, Color* const color) { + colors.insert(index, color); +} + +void Palette::append(Color* const color) { + colors.append(color); +} + +void Palette::remove(const int index) { + colors.remove(index); +} + +int Palette::length() const { + return (int)colors.count(); +} + +Color* Palette::color(const int index) { + return colors.at(index); +} + +Palette Palette::copy(const int index, const int length) { + Palette newPalette; + for(int colorIndex = index; colorIndex < index + length; ++colorIndex) + newPalette.append(new Color( *color(colorIndex) )); + newPalette.setName(name()); + return newPalette; +} + +Palette Palette::cut(const int index, const int length) { + Palette newPalette; + for(int colorNum = 0; colorNum < length; ++colorNum) { + newPalette.append(new Color( *color(index) )); + remove(index); + } + newPalette.setName(name()); + return newPalette; +} + +void Palette::paste(const int index, Palette& palette) { + for(int colorIndex = 0; colorIndex < palette.length(); ++colorIndex) + insert(index + colorIndex, new Color( *palette.color(colorIndex) )); +} + +bool Palette::load(QTextStream& stream, bool loadName /* = true */) { + bool result = true; + setName("KDE palette"); + int lineNum = 0; + while (!stream.atEnd()) { + QString string = stream.readLine().append(' '); + if(string.find( QRegExp("[^\\s]") ) == -1 || + string.stripWhiteSpace().at( 0 ) == '#' || + ( loadName && lineNum == 0 )) { + if(loadName && lineNum == 0) + setName(string.stripWhiteSpace()); + } else { + Color* newColor = new Color(); + int position = string.find(QRegExp( "[^\\s]" )); + for(int componentIndex = 0; componentIndex < Color::COMPONENTS_NUM; + ++componentIndex) { + if(position == -1) { + m_errorString = i18n("Invalid format"); + result = false; + break; + } + int endPosition = string.find(QRegExp( "\\s" ), position); + if(endPosition == -1) { + m_errorString = i18n("Invalid format"); + result = false; + break; + } + QString componentString = string.mid(position, endPosition - position); + int componentValue = componentString.toInt(&result); + if(!result || + componentValue < 0 || + componentValue > RGB_MAX_COMPONENT_VALUE) { + m_errorString = i18n("Invalid format"); + result = false; + break; + } + newColor->setComponent(componentIndex, componentValue); + position = string.find(QRegExp( "[^\\s]" ), endPosition); + } + if(!result) { + delete newColor; + break; + } + if(position != -1) + newColor->setName(string.mid( position ).stripWhiteSpace()); + colors.append(newColor); + } + ++lineNum; + } + if(!result) + deleteContents(); + return result; +} + +bool Palette::load(const QString& fileName) { + bool result = true; + QFile file(fileName); + if(!file.open( IO_ReadOnly )) { + m_errorString = i18n("Could not open file"); + result = false; + } else { + QTextStream stream(&file); + result = load(stream); + file.close(); + } + return result; +} + +bool Palette::save(QTextStream& stream, const QFile* file /* = 0 */, + bool saveName /* = true */) { + bool result = true; + if(saveName) + stream << name() + QString("\n"); + if(file && file->status() != IO_Ok) { + m_errorString = i18n("Write error"); + result = false; + } else + for(int colorIndex = 0; colorIndex < length(); ++colorIndex) { + Color* col = color(colorIndex); + QString redComponentString; + QString greenComponentString; + QString blueComponentString; + redComponentString.setNum(col->component( Color::RED_INDEX )); + greenComponentString.setNum(col->component( Color::GREEN_INDEX )); + blueComponentString.setNum(col->component( Color::BLUE_INDEX )); + QString nameString = col->name(); + if(!nameString.isEmpty()) + nameString.prepend(" "); + stream << redComponentString + QString(" ") + + greenComponentString + QString(" ") + + blueComponentString + + nameString + QString("\n"); + if(file && file->status() != IO_Ok) { + m_errorString = i18n("Write error"); + result = false; + break; + } + } + return result; +} + +bool Palette::save(const QString& fileName) { + bool result = true; + QFile file(fileName); + if(!file.open( IO_WriteOnly|IO_Truncate )) { + m_errorString = i18n("Could not open file for writing"); + result = false; + } else { + QTextStream stream(&file); + result = save(stream); + file.close(); + } + return result; +} + +void Palette::deleteContents() { + colors.clear(); +} + +const QString& Palette::errorString() const { + return m_errorString; +} diff --git a/kcoloredit/palette.h b/kcoloredit/palette.h new file mode 100644 index 00000000..7b763296 --- /dev/null +++ b/kcoloredit/palette.h @@ -0,0 +1,102 @@ +/*************************************************************************** + palette.h - description + ------------------- + begin : Sat Jul 8 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef PALETTE_H +#define PALETTE_H + +#include <qstring.h> +#include <qtextstream.h> +#include <qfile.h> + +#include "color.h" + +/**This class holds a palette. + *@author Artur Rataj + */ +class Palette { +public: + /** Constructs an empty palette */ + Palette(); + /** The copy constructor */ + Palette(const Palette& palette); + ~Palette(); + /** @return A list of KDE palettes */ + static QStringList kdePalettes(); + /** sets palette name */ + void setName(const QString& name); + /** @return palette name */ + const QString& name() const; + /** inserts a color at a given position */ + void insert(const int index, Color* const color); + /** appends a color */ + void append(Color* const color); + /** removes a color at index */ + void remove(const int index); + /** @return the number of colors */ + int length() const; + /** @return color at index */ + Color* color(const int index); + /** @return a copy of palette at index, of length length */ + Palette copy(const int index, const int length); + /** cuts a palette at index, of length length + * @return a palette that has been cut out + */ + Palette cut(const int index, const int length); + /** pastes a palette at index */ + void paste(const int index, Palette& palette); + /** Loads a palette from a text stream + * @return whether the load was succesfull + */ + bool load(QTextStream& stream, bool loadName = true); + /** Loads a palette from a file. + * If loadName is true, palette name is expected. + * @return whether the load was succesfull + */ + bool load(const QString& fileName); + /** Saves a palette into a text stream. + * If file is given, it is checked for IO errors. + * If saveName is true, palette name is saved. + * @return whether save was succesfull + */ + bool save(QTextStream& stream, const QFile* file = 0, bool saveName = true); + /** Saves a palette to a file + * @return whether save was succesfull + */ + bool save(const QString& fileName); + /** Deletes contents of the palette */ + void deleteContents(); + /** @return A possible error description from the last unsuccessfull + * IO operation + */ + const QString& errorString() const; + +private: + /** The palette name */ + QString m_name; + +private: + /** Initialization method called by constructors */ + void init(); + +protected: + /** A list of palette colors */ + QPtrList<Color> colors; + /** An IO error description */ + QString m_errorString; +}; + +#endif diff --git a/kcoloredit/palettehistory.h b/kcoloredit/palettehistory.h new file mode 100644 index 00000000..8bb63643 --- /dev/null +++ b/kcoloredit/palettehistory.h @@ -0,0 +1,26 @@ +/*************************************************************************** + palettehistory.h - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef __PALETTE_HISTORY_H__ +#define __PALETTE_HISTORY_H__ + +#include "editablestreamhistory.h" + +/** Definition of PaletteHistory type */ +typedef EditableStreamHistory<Palette> PaletteHistory; + +#endif /* !defined( __PALETTE_HISTORY_H__ ) */ diff --git a/kcoloredit/paletteview.cpp b/kcoloredit/paletteview.cpp new file mode 100644 index 00000000..8e05a2d7 --- /dev/null +++ b/kcoloredit/paletteview.cpp @@ -0,0 +1,75 @@ +/*************************************************************************** + paletteview.cpp - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <qlayout.h> + +#include "kcoloreditview.h" +#include "paletteview.h" + +PaletteView::PaletteView(const int defaultCellWidth, const int defaultCellHeight, const int cellSpacing, + KColorEditView* view, QWidget *parent, const char *name) : + QFrame(parent, name, QWidget::WResizeNoErase*0) { + setFrameStyle(StyledPanel|Sunken); + setLineWidth(2); + QGridLayout* topLayout = new QGridLayout(this, 2, 2); + topLayout->setMargin(2); + topLayout->setRowStretch(0, 10); + topLayout->setRowStretch(1, 0); + topLayout->setColStretch(0, 10); + topLayout->setColStretch(1, 0); + scrollBar = new QScrollBar(this); + hScrollBar = new QScrollBar(0, 1, 1, 1, 0, QScrollBar::Horizontal, this); + scrolledArea = new PaletteViewScrolledArea(defaultCellWidth, + defaultCellHeight, cellSpacing, scrollBar, hScrollBar, view, this); + connect(scrollBar, SIGNAL( valueChanged(int) ), + SLOT( slotRepaintScrolledArea() )); + topLayout->addWidget(scrolledArea, 0, 0); + connect(hScrollBar, SIGNAL( valueChanged(int) ), + SLOT( slotRepaintScrolledArea() )); + QHBoxLayout* hScrollBarLayout = new QHBoxLayout(); + hScrollBarLayout->addWidget(hScrollBar, 10); + hScrollBarLayout->addWidget(new QWidget(this), 0); + topLayout->addLayout(hScrollBarLayout, 1, 0); + topLayout->addWidget(scrollBar, 0, 1); +} + +PaletteView::~PaletteView() { +} + +void PaletteView::redraw() { + slotRepaintScrolledArea(); +} + +void PaletteView::setScrollBarValue(const int value) { + scrollBar->setValue(value); + hScrollBar->setValue(0); +} + +void PaletteView::slotViewColorNames(bool viewColorNames) { + scrolledArea->slotViewColorNames(viewColorNames); + setScrollBarValue(0); + scrolledArea->redraw(); +} + +void PaletteView::slotCursorFollowsChosenColor(bool follows) { + scrolledArea->slotCursorFollowsChosenColor(follows); +} + +void PaletteView::slotRepaintScrolledArea() { + scrolledArea->redraw(); +} +#include "paletteview.moc" diff --git a/kcoloredit/paletteview.h b/kcoloredit/paletteview.h new file mode 100644 index 00000000..0032997f --- /dev/null +++ b/kcoloredit/paletteview.h @@ -0,0 +1,64 @@ +/*************************************************************************** + paletteview.h - description + ------------------- + begin : Sun Jul 9 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef PALETTEVIEW_H +#define PALETTEVIEW_H + +#include <qframe.h> +#include <qscrollbar.h> + +#include "paletteviewscrolledarea.h" + +class KColorEditView; + +/** This is a Palette class view widget. + * Its parent is KColorEditView + * @author Artur Rataj + */ +class PaletteView : public QFrame { + Q_OBJECT + +public: + /** Constructs a palette view widget, with a default cells sizes and spacing. + * The effective cell sizes may be adjusted to fit the widget sizes. + */ + PaletteView(const int defaultCellWidth, const int defaultCellHeight, const int cellSpacing, + KColorEditView* view, QWidget *parent = 0, const char *name=0); + ~PaletteView(); + /** Calls redraw() in scrolledArea */ + void redraw(); + /** Sets a scroll bar value */ + void setScrollBarValue(const int value); + /** Sets whether to view color names */ + void slotViewColorNames(bool viewColorNames); + +public slots: + /** Sets if the cursor follows a chosen color */ + void slotCursorFollowsChosenColor(bool follows); + /** Repaints the scrolled area */ + void slotRepaintScrolledArea(); + +protected: + /** The scrolled area */ + PaletteViewScrolledArea* scrolledArea; + /** The scroll bar widget */ + QScrollBar* scrollBar; + /** The horizontal scroll bar widget */ + QScrollBar* hScrollBar; +}; + +#endif diff --git a/kcoloredit/paletteviewscrolledarea.cpp b/kcoloredit/paletteviewscrolledarea.cpp new file mode 100644 index 00000000..dafb4d10 --- /dev/null +++ b/kcoloredit/paletteviewscrolledarea.cpp @@ -0,0 +1,409 @@ +/*************************************************************************** + paletteviewscrolledarea.cpp + ------------------- + begin : Sun Jul 17 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <stdlib.h> +#include <qptrlist.h> +#include <qcolor.h> +#include <qcursor.h> +#include <qbrush.h> +#include <qpainter.h> +#include <qpixmap.h> +#include <qpen.h> +#include <qfontmetrics.h> +#include <qtimer.h> +#include <kglobal.h> +#include <kcolordrag.h> +#include <qscrollbar.h> + +#include "palette.h" +#include "palettehistory.h" +#include "kcoloreditdoc.h" +#include "kcoloreditview.h" +#include "paletteviewscrolledarea.h" +#include "paletteviewscrolledarea.moc" + +PaletteViewScrolledArea::PaletteViewScrolledArea(const int defaultCellWidth, + const int defaultCellHeight, const int cellSpacing, QScrollBar* scrollBar, + QScrollBar* hScrollBar, KColorEditView* view, QWidget* parent, const char* name) + : QFrame(parent, name) { + this->defaultCellWidth = defaultCellWidth; + this->defaultCellHeight = defaultCellHeight; + this->cellSpacing = cellSpacing; + this->scrollBar = scrollBar; + this->hScrollBar = hScrollBar; + this->view = view; + setBackgroundMode(NoBackground); + scrollTimeoutTimer = new QTimer(this); + connect(scrollTimeoutTimer, SIGNAL( timeout() ), SLOT( slotScrollTimeout() )); + scrollTimeout = true; + mousePressed = false; + cursorPositioning = false; + colorChosen = false; + setCellsSizes(); + slotCursorFollowsChosenColor(false); + this->scrollBar->setValue(0); + slotViewColorNames(false); + setMinimumSize(1, 1); +} + +PaletteViewScrolledArea::~PaletteViewScrolledArea() { +} + +void PaletteViewScrolledArea::slotCursorFollowsChosenColor(bool follows) { + cursorFollowsChosenColor = follows; +} + +void PaletteViewScrolledArea::slotViewColorNames(bool viewColorNames) { + this->viewColorNames = viewColorNames; +} + +void PaletteViewScrolledArea::redraw() { + //setCellsSizes(); + repaintPalette(); +} + +void PaletteViewScrolledArea::repaintPalette() { + repaint(false); +} + +void PaletteViewScrolledArea::checkSelectionAutoScroll(const int mousePosY) { + if(mousePosY < 0) + scrollPalette(-8, 50); + else if(mousePosY > height() - 1) + scrollPalette(8, 50); +} + +void PaletteViewScrolledArea::scrollPalette(const int amount, const int timeout) { + if(scrollTimeout) { + scrollBy(amount); + scrollTimeout = false; + scrollTimeoutTimer->start(timeout, true); + } +} + +void PaletteViewScrolledArea::slotScrollTimeout() { + scrollTimeout = true; + if(mousePressed) { + QPoint cursorPoint = mapFromGlobal(QCursor::pos()); + setCursorPos(cursorPoint.x(), cursorPoint.y()); + selectionEnd = cursorPos(); + if(selectionEnd >= selectionBegin) + setSelection(selectionBegin, selectionEnd); + else + setSelection(selectionEnd, selectionBegin); + checkSelectionAutoScroll(cursorPoint.y()); + repaintPalette(); + } +} + +void PaletteViewScrolledArea::setCursorPos(const int pos) { + int oldCursorPos = document()->paletteCursorPos(); + document()->setPaletteCursorPos(pos); + if(pos != oldCursorPos) + view->slotCursorPosChanged(pos); +} + +bool PaletteViewScrolledArea::setCursorPos(const int x, const int y) { + int shiftedY = y + scrollBar->value(); + int shiftedX = x + hScrollBar->value(); + int cursorColumn = (shiftedX + rowWidth/cellsInRow/2)*cellsInRow/rowWidth; + int cursorRow; + if(shiftedY >= 0) + cursorRow = (shiftedY + cellSpacing)/rowHeight; + else + cursorRow = -1; + bool atCursorLocation = abs(cursorColumn*rowWidth/cellsInRow - shiftedX) < cellSpacing + 1; + if(!atCursorLocation) { + atCursorLocation = abs(cursorRow*rowHeight - shiftedY) < cellSpacing + 1; + if(atCursorLocation) + cursorColumn = 0; + } + if(atCursorLocation || cursorPositioning) { + if(cursorColumn > cellsInRow - 1) { + cursorColumn = 0; + ++cursorRow; + } + int tmpCursorPos = cursorRow*cellsInRow + cursorColumn; + if(tmpCursorPos < 0) + tmpCursorPos = 0; + else if(tmpCursorPos >= palette()->length()) { + if(tmpCursorPos == palette()->length() && + cursorColumn == 0 && + selectionMin() == selectionMax()) + /* if cursor has been set after the last color and the color is + * also the last in a row, and there is no selection, scroll the + * palette to ensure the cursor is visible + */ + scrollBy(rowHeight*2); + if(tmpCursorPos > palette()->length()) + tmpCursorPos = palette()->length(); + } + setCursorPos(tmpCursorPos); + } + return atCursorLocation; +} + +void PaletteViewScrolledArea::setSelection(const int min, const int max) { + document()->setPaletteSelection(min, max); +} + +void PaletteViewScrolledArea::setCellsSizes() { + rowWidth = width(); + cellWidth = defaultCellWidth; + cellHeight = defaultCellHeight; + if(viewColorNames) { + QPainter painter; + painter.begin(this); + if(cellHeight < painter.fontMetrics().height()) { + int prevCellHeight = cellHeight; + cellHeight = painter.fontMetrics().height(); + cellWidth = cellHeight*cellWidth/prevCellHeight; + } + painter.end(); + } + if(viewColorNames) + cellsInRow = 1; + else + cellsInRow = rowWidth/(cellWidth + cellSpacing*2); + if(viewColorNames) + rowHeight = cellHeight + cellSpacing*2; + else + rowHeight = (int)(rowWidth*1.0/cellsInRow/ + ( cellWidth + cellSpacing*2 )*( cellHeight + cellSpacing*2 ) + 0.5); + cellHeight = rowHeight - cellSpacing*2; + rowsNum = (palette()->length() + cellsInRow - 1)/cellsInRow; + cellTableHeight = rowsNum*rowHeight; + int contentsHeight; + if(palette()->length() != 0 && + ( palette()->length()%cellsInRow ) == 0) + contentsHeight = cellTableHeight + rowHeight; + else + contentsHeight = cellTableHeight; + int scrollBarRange = contentsHeight - 1 - height(); + if(scrollBarRange < 0) + scrollBarRange = 0; + scrollBar->setRange(0, scrollBarRange); + scrollBar->setSteps(rowHeight, height()); +} + +Palette* PaletteViewScrolledArea::palette() const { + return document()->paletteHistory()->editableStream(); +} + +int PaletteViewScrolledArea::cursorPos() const { + return document()->paletteCursorPos(); +} + +int PaletteViewScrolledArea::selectionMin() const{ + return document()->paletteSelectionBegin(); +} + +int PaletteViewScrolledArea::selectionMax() const { + return document()->paletteSelectionEnd(); +} + +void PaletteViewScrolledArea::paintEvent(QPaintEvent* /*event*/) { + setCellsSizes(); + QPixmap pixmap(size()); + QPainter painter; + painter.begin(&pixmap, this); + QFontMetrics fontMetrics = painter.fontMetrics(); + int maxLineWidth; + if(viewColorNames) { + int maxTextLength = 0; + for(int index = 0; index < palette()->length(); ++index) { + int currTextLength = fontMetrics.width( + palette()->color(index)->name()); + if(currTextLength > maxTextLength) + maxTextLength = currTextLength; + } + maxLineWidth = cellWidth + cellSpacing*2 + + cellSpacing*3 + maxTextLength + 1; + } else + maxLineWidth = rowWidth; + int width = rowWidth; + if(maxLineWidth > width) { + hScrollBar->setRange(0, maxLineWidth - width); + hScrollBar->setSteps(8, width); + hScrollBar->show(); + } else { + hScrollBar->setValue(0); + hScrollBar->hide(); + } + int posY = scrollBar->value(); + int firstRow = posY/rowHeight; + int lastRow = (posY + height() - 1 + rowHeight - 1)/rowHeight; + if(viewColorNames) + painter.fillRect(0, 0, rowWidth, height(), + QBrush( QFrame::palette().active().base() )); + QBrush normalBackgroundBrush(QFrame::palette().active().background()); + QBrush selectedBackgroundBrush(QFrame::palette().active().highlight()); + QBrush foregroundBrush; + QBrush cursorBrush(QFrame::palette().active().foreground()); + QPen backgroundPen(QFrame::palette().active().foreground()); + int min = selectionMin(); + int max = selectionMax(); + int fontAscent = fontMetrics.ascent(); + int xBegin = -hScrollBar->value(); + for(int x = 0; x < cellsInRow; ++x) { + int xEnd = -hScrollBar->value(); + if(viewColorNames) + xEnd += cellWidth + cellSpacing*2; + else + xEnd += (x + 1)*(width - 1)/cellsInRow; + int cellWithSpacingWidth = xEnd - xBegin + 1; + int cellWidth = cellWithSpacingWidth - 2*cellSpacing; + for(int y = firstRow; y <= lastRow; ++y) { + int yBegin = y*rowHeight - posY; + int currCellNum = y*cellsInRow + x; + QBrush* backgroundBrush; + if(currCellNum >= min && currCellNum < max) + backgroundBrush = &selectedBackgroundBrush; + else + backgroundBrush = &normalBackgroundBrush; + if(currCellNum < palette()->length()) { + Color* color = palette()->color(currCellNum); + QBrush foregroundBrush(QColor( + color->component(Color::RED_INDEX), + color->component(Color::GREEN_INDEX), + color->component(Color::BLUE_INDEX) )); + painter.fillRect(xBegin, yBegin, cellWithSpacingWidth, cellSpacing, + *backgroundBrush); + painter.fillRect(xBegin, yBegin + rowHeight - cellSpacing, cellWithSpacingWidth, cellSpacing, + *backgroundBrush); + QBrush* backgroundOrCursorBrush; + if(cursorPos() == currCellNum) + backgroundOrCursorBrush = &cursorBrush; + else + backgroundOrCursorBrush = backgroundBrush; + painter.fillRect(xBegin, yBegin + cellSpacing, cellSpacing, cellHeight, + *backgroundOrCursorBrush); + painter.fillRect(xBegin + cellWithSpacingWidth - cellSpacing, yBegin + cellSpacing, + cellSpacing, cellHeight, + *backgroundBrush); + painter.fillRect(xBegin + cellSpacing, yBegin + cellSpacing, cellWidth, cellHeight, + foregroundBrush); + if(viewColorNames) { + painter.setPen(backgroundPen); + painter.drawText(xBegin + cellWithSpacingWidth + cellSpacing*3, + yBegin + rowHeight/2 + fontAscent/2, color->name()); + } + } else { + if(cursorPos() == currCellNum) { + painter.fillRect(xBegin, yBegin + cellSpacing, cellSpacing, cellHeight, + cursorBrush); + painter.fillRect(xBegin, yBegin, cellSpacing, cellSpacing, + *backgroundBrush); + painter.fillRect(xBegin, yBegin + rowHeight - cellSpacing, cellSpacing, cellSpacing, + *backgroundBrush); + painter.fillRect(xBegin + cellSpacing, yBegin, cellWithSpacingWidth - cellSpacing, rowHeight, + *backgroundBrush); + } else + painter.fillRect(xBegin, yBegin, cellWithSpacingWidth, rowHeight, + *backgroundBrush); + } + } + xBegin = xEnd + 1; + } + painter.end(); + painter.begin(this); + painter.drawPixmap(0, 0, pixmap); + painter.end(); +} + +int PaletteViewScrolledArea::colorIndex(const QPoint& point) const { + int colorColumn = point.x()*cellsInRow/rowWidth; + int colorRow = (point.y() + scrollBar->value())/rowHeight; + int colorIndex = colorRow*cellsInRow + colorColumn; + if(colorIndex > palette()->length() - 1 || + colorIndex < 0) + colorIndex = -1; + return colorIndex; +} + +QColor PaletteViewScrolledArea::color(const QPoint& point) const { + Color* color = palette()->color(colorIndex( point )); + return QColor(color->component( Color::RED_INDEX ), + color->component( Color::GREEN_INDEX ), + color->component( Color::BLUE_INDEX )); +} + +void PaletteViewScrolledArea::mousePressEvent(QMouseEvent* event) { + cursorPositioning = false; + if(( cursorPositioning = setCursorPos(event->x(), event->y()) )) { + selectionBegin = cursorPos(); + setSelection(selectionBegin, selectionBegin); + redraw(); + colorChosen = false; + } else { + colorDragPoint = event->pos(); + colorChosen = true; + } + mousePressed = true; +} + +void PaletteViewScrolledArea::mouseMoveEvent(QMouseEvent* event) { + if(cursorPositioning) { + setCursorPos(event->x(), event->y()); + selectionEnd = cursorPos(); + if(selectionEnd >= selectionBegin) + setSelection(selectionBegin, selectionEnd); + else + setSelection(selectionEnd, selectionBegin); + checkSelectionAutoScroll(event->y()); + redraw(); + } else { + /* check if it is a color drag */ + if(colorIndex( colorDragPoint ) != -1) { + if(abs( event->x() - colorDragPoint.x() ) > 2 || + abs( event->y() - colorDragPoint.y() ) > 2) { + QColor draggedColor = color(colorDragPoint); + KColorDrag* colorDrag = KColorDrag::makeDrag(draggedColor, this); + colorDrag->dragCopy(); + } else + colorChosen = true; + } + } +} + +void PaletteViewScrolledArea::mouseReleaseEvent(QMouseEvent* /*event*/) { + if(colorChosen) { + if(colorIndex( colorDragPoint ) != -1) { + int index = colorIndex(colorDragPoint); + chooseColor(palette()->color( index )); + if(cursorFollowsChosenColor) { + setCursorPos(index); + setSelection(cursorPos(), cursorPos()); + redraw(); + } + } + colorChosen = false; + } + mousePressed = false; +} + +void PaletteViewScrolledArea::chooseColor(Color* const color) { + view->chooseColor(color); +} + +KColorEditDoc* PaletteViewScrolledArea::document() const { + return view->document(); +} + +void PaletteViewScrolledArea::scrollBy(const int y) { + scrollBar->setValue(scrollBar->value() + y); +} diff --git a/kcoloredit/paletteviewscrolledarea.h b/kcoloredit/paletteviewscrolledarea.h new file mode 100644 index 00000000..18bbae2b --- /dev/null +++ b/kcoloredit/paletteviewscrolledarea.h @@ -0,0 +1,162 @@ +/*************************************************************************** + paletteviewscrolledarea.h + ------------------- + begin : Sun Jul 17 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef PALETTEVIEWSCROLLEDAREA_H +#define PALETTEVIEWSCROLLEDAREA_H + +#include <qframe.h> +#include <qevent.h> + +#include "palette.h" + +class KColorEditDoc; +class KColorEditView; +class QScrollBar; + +/** This widget draws the palette view scrolled area. + * It has paste and cut features. + * @author Artur Rataj + */ +class PaletteViewScrolledArea : public QFrame { + Q_OBJECT + +public: + /** Constructs the widget */ + PaletteViewScrolledArea(const int defaultCellWidth, const int defaultCellHeight, + const int cellSpacing, QScrollBar* scrollBar, + QScrollBar* hScrollBar, KColorEditView* view, + QWidget* parent = 0, const char* name = 0); + ~PaletteViewScrolledArea(); + /** Sets cells sizes and then calls repaintPalette() */ + void redraw(); + +public slots: + /** Sets if the cursor follows a chosen color */ + void slotCursorFollowsChosenColor(bool follows); + /** Sets whether to view color names */ + void slotViewColorNames(bool viewColorNames); + +protected: + /** The scrollbar widget */ + QScrollBar* scrollBar; + /** The horizontal scrollbar widget */ + QScrollBar* hScrollBar; + /** Pointer to the document view */ + KColorEditView* view; + /** Default cell width */ + int defaultCellWidth; + /** Default cell height */ + int defaultCellHeight; + /** Cell spacing */ + int cellSpacing; + /** Cell width */ + int cellWidth; + /** Cell height */ + int cellHeight; + /** The number of cells in a row */ + int cellsInRow; + /** The number of rows */ + int rowsNum; + /** A row width */ + int rowWidth; + /** A row height */ + int rowHeight; + /** Total height of cells table */ + int cellTableHeight; + /** A position at which selection started */ + int selectionBegin; + /** A position at which selection ended */ + int selectionEnd; + /** Auto scroll timeout timer */ + QTimer* scrollTimeoutTimer; + /** Whether there is auto scroll timeout */ + bool scrollTimeout; + /** Whether a mouse has been pressed over the palette and not yet released */ + bool mousePressed; + /** Whether the cursor is being positioned */ + bool cursorPositioning; + /** A color drag point */ + QPoint colorDragPoint; + /** Whether a color has been chosen and it is not dragged */ + bool colorChosen; + /** Whether the cursor follows a chosen color */ + bool cursorFollowsChosenColor; + /** Whether to view color names */ + bool viewColorNames; + + /** @return The viewed palette */ + Palette* palette() const; + /** Computes the size of cell, number of cells in a row and + * height of cells table, depending on colors number and + * visible area width + */ + void setCellsSizes(); + /** repaints the palette */ + void repaintPalette(); + /** @return A color index at a given position, -1 if none */ + int colorIndex(const QPoint& point) const; + /** @return A color at a given position */ + QColor color(const QPoint& point) const; + /** sets a palette cursor position */ + void setCursorPos(const int pos); + /** Sets a cursor position due to a mouse position. + * If not in cursor positioning, the cursor is set + * only if mouse points to a possible cursor location + * @return If the mouse points to a cursor location + */ + bool setCursorPos(const int x, const int y); + /** @return a palette cursor position */ + int cursorPos() const; + /** sets a palette selection */ + void setSelection(const int min, const int max); + /** @return a palette selection lesser position, or equal position + * if no colors are selected + */ + int selectionMin() const; + /** @return a palette selection greater position, or equal position + * if no colors are selected + */ + int selectionMax() const; + /** checks whether to scrolls the palette if a mouse position + * is outside it + */ + void checkSelectionAutoScroll(const int mousePosY); + /** The widget painting */ + void paintEvent(QPaintEvent* event); + /** Used to get mouse press events coordinates */ + void mousePressEvent(QMouseEvent* event); + /** Used to get mouse move events coordinates */ + void mouseMoveEvent(QMouseEvent* event); + /** Used to get mouse release events coordinates */ + void mouseReleaseEvent(QMouseEvent* event); + /** If there is a scroll timeout, scrolls palette, + * sets scrollTimeout to false and resets scroll timeout timer + */ + void scrollPalette(const int amount, const int timeout); + /** @return The viewed document */ + KColorEditDoc* document() const; + /** Chooses a color to the color selector */ + void chooseColor(Color* const color); + /** scrolls the scrolled area */ + void scrollBy(const int y); + +protected slots: + /** called if there is a scroll timeout, sets scrollTimeout to true */ + void slotScrollTimeout(); +}; + +#endif /* !defined( PALETTEVIEWSCROLLEDAREA_H ) */ diff --git a/kcoloredit/resource.h b/kcoloredit/resource.h new file mode 100644 index 00000000..c96576cc --- /dev/null +++ b/kcoloredit/resource.h @@ -0,0 +1,35 @@ +/*************************************************************************** + resource.h - description + ------------------- + begin : Sat Jul 8 09:57:28 CEST 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef RESOURCE_H +#define RESOURCE_H + +#ifdef HAVE_CONFIG_H +#include <config.h> +#endif + +/////////////////////////////////////////////////////////////////// +// resource.h -- contains macros used for commands + + +/////////////////////////////////////////////////////////////////// +// General application values +#define ID_STATUS_MSG 1001 + +#define IDS_STATUS_DEFAULT I18N_NOOP("Ready.") + +#endif // RESOURCE_H diff --git a/kcoloredit/texteditselection.cpp b/kcoloredit/texteditselection.cpp new file mode 100644 index 00000000..65d4ecad --- /dev/null +++ b/kcoloredit/texteditselection.cpp @@ -0,0 +1,187 @@ +/*************************************************************************** + texteditselection.cpp - description + ------------------- + begin : Wed Jul 12 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include <qlabel.h> +#include <qvalidator.h> +#include <qcolor.h> + +#include <klocale.h> + +#include "main.h" +#include "texteditselection.h" + +TextEditSelection::TextEditSelection(QWidget *parent, const char *name ) : QWidget(parent,name) { + inChangingComponents = false; + QVBoxLayout* topLayout = new QVBoxLayout(this, 4); + QGridLayout* componentsLayout = new QGridLayout(3, 5, 2); + topLayout->addLayout(componentsLayout); + componentsLayout->setColStretch(1, 10); + componentsLayout->addColSpacing(2, 8); + componentsLayout->setColStretch(4, 10); + QLineEdit* lineEdit; + addComponent(H_INDEX, ( lineEdit = new QLineEdit(this) ), HSV_MAX_H_VALUE, "H:", 0, 0, componentsLayout); + connect(lineEdit, SIGNAL( textChanged(const QString&) ), SLOT( slotHsvComponentChanged() )); + addComponent(S_INDEX, ( lineEdit = new QLineEdit(this) ), HSV_MAX_S_VALUE, "S:", 1, 0, componentsLayout); + connect(lineEdit, SIGNAL( textChanged(const QString&) ), SLOT( slotHsvComponentChanged() )); + addComponent(V_INDEX, ( lineEdit = new QLineEdit(this) ), HSV_MAX_V_VALUE, "V:", 2, 0, componentsLayout); + connect(lineEdit, SIGNAL( textChanged(const QString&) ), SLOT( slotHsvComponentChanged() )); + addComponent(R_INDEX, ( lineEdit = new QLineEdit(this) ), RGB_MAX_COMPONENT_VALUE, "R:", 0, 1, componentsLayout); + connect(lineEdit, SIGNAL( textChanged(const QString&) ), SLOT( slotRgbComponentChanged() )); + addComponent(G_INDEX, ( lineEdit = new QLineEdit(this) ), RGB_MAX_COMPONENT_VALUE, "G:", 1, 1, componentsLayout); + connect(lineEdit, SIGNAL( textChanged(const QString&) ), SLOT( slotRgbComponentChanged() )); + addComponent(B_INDEX, ( lineEdit = new QLineEdit(this) ), RGB_MAX_COMPONENT_VALUE, "B:", 2, 1, componentsLayout); + connect(lineEdit, SIGNAL( textChanged(const QString&) ), SLOT( slotRgbComponentChanged() )); + QHBoxLayout* rgbStringLayout = new QHBoxLayout(2); + QLabel* rgbStringLabel = new QLabel("RGB " + i18n( "hex." ) + ": ", this); + rgbStringLayout->addWidget(rgbStringLabel); + rgbStringLineEdit = new QLineEdit(this); + rgbStringLineEdit->setMinimumWidth(lineEdit->fontMetrics().width( QString("8888888") )); + rgbStringLineEdit->setMaximumWidth(lineEdit->fontMetrics().width( QString("888888888") )); + connect(rgbStringLineEdit, SIGNAL( textChanged(const QString&) ), SLOT( slotRgbStringChanged() )); + rgbStringLayout->addWidget(rgbStringLineEdit); + topLayout->addLayout(rgbStringLayout); +} +TextEditSelection::~TextEditSelection(){ +} + +void TextEditSelection::addComponent(const int index, QLineEdit* lineEdit, const int maxValue, + const QString& labelString, const int row, const int column, QGridLayout* layout) { + QLabel* label = new QLabel(labelString, this); + lineEdit->setValidator(new QIntValidator( 0, maxValue, lineEdit )); + lineEditTable[index] = lineEdit; + lineEdit->setMinimumWidth(lineEdit->fontMetrics().width( QString("8888") )); + lineEdit->setMaximumWidth(lineEdit->fontMetrics().width( QString("8888888") )); + layout->addWidget(label, row, column*3); + layout->addWidget(lineEdit, row, column*3 + 1); +} + +void TextEditSelection::setRgbString(const int red, const int green, const int blue) { + QString string; + string.sprintf("%02x%02x%02x", red, green, blue); + rgbStringLineEdit->setText(string); +} + +void TextEditSelection::slotHsvComponentChanged() { + if(!inChangingComponents) { + inChangingComponents = true; + int hComponent = lineEditTable[H_INDEX]->text().toInt(); + int sComponent = lineEditTable[S_INDEX]->text().toInt(); + int vComponent = lineEditTable[V_INDEX]->text().toInt(); + QColor color; + color.setHsv(hComponent, sComponent, vComponent); + int rComponent = color.red(); + int gComponent = color.green(); + int bComponent = color.blue(); + QString string; + lineEditTable[R_INDEX]->setText(string.setNum( rComponent )); + lineEditTable[G_INDEX]->setText(string.setNum( gComponent )); + lineEditTable[B_INDEX]->setText(string.setNum( bComponent )); + Color oldColor = this->color; + this->color.setComponent(Color::RED_INDEX, rComponent); + this->color.setComponent(Color::GREEN_INDEX, gComponent); + this->color.setComponent(Color::BLUE_INDEX, bComponent); + if(!this->color.equals( oldColor )) + emit valueChanged(&this->color); + setRgbString(rComponent, gComponent, bComponent); + inChangingComponents = false; + } +} + +void TextEditSelection::slotRgbComponentChanged() { + if(!inChangingComponents) { + inChangingComponents = true; + int rComponent = lineEditTable[R_INDEX]->text().toInt(); + int gComponent = lineEditTable[G_INDEX]->text().toInt(); + int bComponent = lineEditTable[B_INDEX]->text().toInt(); + QColor color; + color.setRgb(rComponent, gComponent, bComponent); + int hComponent; + int sComponent; + int vComponent; + color.hsv(&hComponent, &sComponent, &vComponent); + QString string; + lineEditTable[H_INDEX]->setText(string.setNum( hComponent )); + lineEditTable[S_INDEX]->setText(string.setNum( sComponent )); + lineEditTable[V_INDEX]->setText(string.setNum( vComponent )); + Color oldColor = this->color; + this->color.setComponent(Color::RED_INDEX, rComponent); + this->color.setComponent(Color::GREEN_INDEX, gComponent); + this->color.setComponent(Color::BLUE_INDEX, bComponent); + if(!this->color.equals( oldColor )) + emit valueChanged(&this->color); + setRgbString(rComponent, gComponent, bComponent); + inChangingComponents = false; + } +} + +void TextEditSelection::slotRgbStringChanged() { + if(!inChangingComponents) { + inChangingComponents = true; + QString string = rgbStringLineEdit->text().stripWhiteSpace(); + bool result; + int value = string.toInt(&result, 16); + if(result) { + int rComponent = (value >> 16)&0xff; + int gComponent = (value >> 8)&0xff; + int bComponent = (value >> 0)&0xff; + lineEditTable[R_INDEX]->setText(string.setNum( rComponent )); + lineEditTable[G_INDEX]->setText(string.setNum( gComponent )); + lineEditTable[B_INDEX]->setText(string.setNum( bComponent )); + int hComponent; + int sComponent; + int vComponent; + QColor hsvColor; + hsvColor.hsv(&hComponent, &sComponent, &vComponent); + lineEditTable[H_INDEX]->setText(string.setNum( hComponent )); + lineEditTable[S_INDEX]->setText(string.setNum( sComponent )); + lineEditTable[V_INDEX]->setText(string.setNum( vComponent )); + Color oldColor = this->color; + this->color.setComponent(Color::RED_INDEX, rComponent); + this->color.setComponent(Color::GREEN_INDEX, gComponent); + this->color.setComponent(Color::BLUE_INDEX, bComponent); + if(!this->color.equals( oldColor )) + emit valueChanged(&this->color); + } + inChangingComponents = false; + } +} + +void TextEditSelection::slotSetValue(Color* color) { + if(!color->equals( this->color )) { + inChangingComponents = true; + this->color = *color; + QString string; + int rComponent = this->color.component(Color::RED_INDEX); + int gComponent = this->color.component(Color::GREEN_INDEX); + int bComponent = this->color.component(Color::BLUE_INDEX); + lineEditTable[R_INDEX]->setText(string.setNum( rComponent )); + lineEditTable[G_INDEX]->setText(string.setNum( gComponent )); + lineEditTable[B_INDEX]->setText(string.setNum( bComponent )); + QColor hsvColor(rComponent, gComponent, bComponent); + int hComponent; + int sComponent; + int vComponent; + hsvColor.hsv(&hComponent, &sComponent, &vComponent); + lineEditTable[H_INDEX]->setText(string.setNum( hComponent )); + lineEditTable[S_INDEX]->setText(string.setNum( sComponent )); + lineEditTable[V_INDEX]->setText(string.setNum( vComponent )); + setRgbString(rComponent, gComponent, bComponent); + inChangingComponents = false; + } +} + +#include "texteditselection.moc" diff --git a/kcoloredit/texteditselection.h b/kcoloredit/texteditselection.h new file mode 100644 index 00000000..c2166098 --- /dev/null +++ b/kcoloredit/texteditselection.h @@ -0,0 +1,89 @@ +/*************************************************************************** + texteditselection.h - description + ------------------- + begin : Wed Jul 12 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#ifndef TEXTEDITSELECTION_H +#define TEXTEDITSELECTION_H + +#include <qwidget.h> +#include <qlineedit.h> +#include <qlayout.h> + +#include "color.h" + +/** Color selection widget using line edit. Either HSV or RGB components + * can be set. + * @author Artur Rataj + */ +class TextEditSelection : public QWidget { + Q_OBJECT + +public: + /** Constructs the widget */ + TextEditSelection(QWidget *parent=0, const char *name=0); + ~TextEditSelection(); + +signals: + /** A signal that a color value has changed by edition */ + void valueChanged(Color*); + +public slots: + /** sets a color */ + void slotSetValue(Color* color); + +protected: + /** Adds a component line edit */ + void addComponent(const int index, QLineEdit* lineEdit, const int maxValue, const QString& labelString, + const int row, const int column, QGridLayout* layout); + /** sets RGB string in rgbStringLineEdit */ + void setRgbString(const int red, const int green, const int blue); + +protected slots: + /** Called if one of HSV components has changed. In that case, RGB components are + * also changed to match the HSV ones + */ + void slotHsvComponentChanged(); + /** Called if one of RGB components has changed. In that case, HSV components are + * also changed to match the RGB ones + */ + void slotRgbComponentChanged(); + /** Called if the RGB string has changed. In that case, RGB and HSV components are + * also changed to match the RGB string + */ + void slotRgbStringChanged(); + +protected: + /** Indexes of components */ + enum { H_INDEX = 0, + S_INDEX = 1, + V_INDEX = 2, + R_INDEX = 3, + G_INDEX = 4, + B_INDEX = 5, + /** A total number of components */ + COMPONENTS_NUM = 6 }; + + /** Line edit widgets table */ + QLineEdit* lineEditTable[COMPONENTS_NUM]; + /** RGB hex string line edit widgets table */ + QLineEdit* rgbStringLineEdit; + /** The selected color */ + Color color; + /** A flag that components are matched */ + bool inChangingComponents; +}; + +#endif diff --git a/kcoloredit/textselection.cpp b/kcoloredit/textselection.cpp new file mode 100644 index 00000000..8a4225bc --- /dev/null +++ b/kcoloredit/textselection.cpp @@ -0,0 +1,24 @@ +/*************************************************************************** + textselection.cpp - description + ------------------- + begin : Wed Jul 12 2000 + copyright : (C) 2000 by Artur Rataj + email : [email protected] + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +#include "textselection.h" + +TextSelection::TextSelection(QWidget *parent, const char *name ) : QWidget(parent,name) { + +} +TextSelection::~TextSelection(){ +} diff --git a/kcoloredit/uninstall.desktop b/kcoloredit/uninstall.desktop new file mode 100644 index 00000000..e1e3e173 --- /dev/null +++ b/kcoloredit/uninstall.desktop @@ -0,0 +1,2 @@ +[Desktop Entry] +Hidden=true |