summaryrefslogtreecommitdiffabout
path: root/microkde
authorzautrix <zautrix>2005-06-18 17:14:20 (UTC)
committer zautrix <zautrix>2005-06-18 17:14:20 (UTC)
commit45c93de5a458e7ca0c293eebe504a9d949cc045c (patch) (unidiff)
treec303812528fbd3fa1868928abfe198471395bb5b /microkde
parent1919ddd25fb835b0eb03a44cbfbf4713d45266b8 (diff)
downloadkdepimpi-45c93de5a458e7ca0c293eebe504a9d949cc045c.zip
kdepimpi-45c93de5a458e7ca0c293eebe504a9d949cc045c.tar.gz
kdepimpi-45c93de5a458e7ca0c293eebe504a9d949cc045c.tar.bz2
color dialog
Diffstat (limited to 'microkde') (more/less context) (ignore whitespace changes)
-rwxr-xr-xmicrokde/fncolordialog.cpp334
-rwxr-xr-xmicrokde/fncolordialog.h137
-rw-r--r--microkde/kcolordialog.cpp80
-rw-r--r--microkde/kcolordialog.h13
-rw-r--r--microkde/microkdeE.pro4
5 files changed, 480 insertions, 88 deletions
diff --git a/microkde/fncolordialog.cpp b/microkde/fncolordialog.cpp
new file mode 100755
index 0000000..f1ffa5b
--- a/dev/null
+++ b/microkde/fncolordialog.cpp
@@ -0,0 +1,334 @@
1/* this program for Sharp SLA300, B500, C7x0, C860 Linux PDA
2 Copyright (C) 2003-2005 Joe Kanemori.<kanemori@ymg.urban.ne.jp>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundatibannwaon; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18
19#include <qwidget.h>
20#include <qimage.h>
21#include <qbrush.h>
22#include <qpainter.h>
23#include <qlabel.h>
24#include "fncolordialog.h"
25
26
27//-----------------------------------------------------------------------------
28// FNPaletteBase
29//-----------------------------------------------------------------------------
30/*
31 * Constructs a Example which is a child of 'parent', with the
32 * name 'name' and widget flags set to 'f'
33 */
34FNPaletteBase::FNPaletteBase(QWidget* parent, const char* name, WFlags fl )
35 : QWidget( parent, name, fl ), bgcolor_(white), _isblock(false)
36{
37 this->setBackgroundMode(NoBackground);
38 wbuf_.resize(32, 32);
39}
40
41/*
42 * Destroys the object and frees any allocated resources
43 */
44FNPaletteBase::~FNPaletteBase()
45{
46 // no need to delete child widgets, Qt does it all for us
47}
48
49
50/*
51 * Painting event.
52 */
53void FNPaletteBase::paintEvent(QPaintEvent*)
54{
55 bitBlt(this, 0, 0, &wbuf_);
56}
57
58
59/*
60 * Painting event.
61 */
62void FNPaletteBase::resizeEvent(QResizeEvent* evt)
63{
64 QPixmap save(wbuf_);
65 wbuf_.resize(evt->size());
66 wbuf_.fill(bgcolor_);
67 bitBlt(&wbuf_, 0, 0, &save);
68 redraw();
69}
70
71
72/*
73 * Redraw method.
74 */
75void FNPaletteBase::redraw(bool force)
76{
77 if (!force) {
78 if (_isblock) {
79 return;
80 }
81 }
82 _isblock = true;
83 wbuf_.fill(bgcolor_);
84 QPainter pa;
85 pa.begin(&wbuf_);
86 drawImpl(pa);
87 pa.end();
88 repaint();
89 _isblock = false;
90}
91
92
93/*
94 * Redraw Implement
95 */
96void FNPaletteBase::drawImpl(QPainter& pa)
97{
98 pa.flush();
99}
100
101bool FNPaletteBase::pickColor(int x, int y)
102{
103 if (0 <= x && 0 <= y && x < width() && y < height()) {
104 selection_ = QColor(wbuf_.convertToImage().pixel(x, y));
105 return true;
106 } else {
107 return false;
108 }
109}
110
111void FNPaletteBase::mouseReleaseEvent(QMouseEvent* evt)
112{
113 //マウスリリースイベント(MouseClicked)
114 if (pickColor(evt->x(), evt->y())) {
115 emit clicked(this);
116 }
117}
118
119
120
121
122//-----------------------------------------------------------------------------
123// FNColorPalette
124//-----------------------------------------------------------------------------
125FNColorPalette::FNColorPalette(QColor c, QWidget* parent, const char* name, WFlags fl)
126:FNPaletteBase(parent, name, fl)
127{
128 setBGColor(c);
129}
130
131FNColorPalette::~FNColorPalette()
132{
133}
134
135
136
137
138//-----------------------------------------------------------------------------
139// FNHSVPalette
140//-----------------------------------------------------------------------------
141FNHSVPalette::FNHSVPalette(QWidget* parent, const char* name, WFlags fl)
142:FNPaletteBase(parent, name, fl), _hue(0)
143{
144}
145
146FNHSVPalette::~FNHSVPalette()
147{
148}
149
150void FNHSVPalette::hueChanged(int v)
151{
152 _hue = v;
153 redraw();
154}
155
156void FNHSVPalette::drawImpl(QPainter& pa)
157{
158 //描画実装
159 //HSVカラーパレットを描画
160 int wd = width();
161 int ht = height();
162 if (wd > 0 && ht > 0) {
163 QColor c;
164 double xs = (double)wd / 255.0;
165 double ys = (double)ht / 255.0;
166 for (int i = 0; i < 256; i += 32) {
167 int x1 = (int)((double)i * xs);
168 int x2 = (int)((double)(i + 32) * xs);
169 int w = x2 - x1;
170 if (1 > w) {
171 w = 1;
172 }
173 for (int j = 0; j <= 256; j += 32) {
174 int y1 = (int)((double)j * ys);
175 int y2 = (int)((double)(j + 32) * ys);
176 int h = y2 - y1;
177 if (1 > h) {
178 h = 1;
179 }
180 c.setHsv(_hue, 255 - j, 255 - i);
181 pa.fillRect(x1, y1, w, h, QBrush(c));
182 }
183 }
184 }
185 pa.flush();
186}
187
188
189
190
191//-----------------------------------------------------------------------------
192// FNColorDialog
193//-----------------------------------------------------------------------------
194FNColorDialog::FNColorDialog(QWidget* parent, const char* name, WFlags f)
195:QDialog(parent, name, true, f), _isblock(false)
196{
197 resize(200, 200);
198 QVBoxLayout* mainlayout = new QVBoxLayout(this);
199 setCaption("Color Selector");
200 mainlayout->setMargin(2);
201 mainlayout->setSpacing(2);
202 setSizeGripEnabled(true);
203 //基本パレット
204 int p = 0;
205 _base[p++] = new FNColorPalette(QColor(0, 0, 0), this);
206 _base[p++] = new FNColorPalette(QColor(0, 0, 255), this);
207 _base[p++] = new FNColorPalette(QColor(255, 0, 0), this);
208 _base[p++] = new FNColorPalette(QColor(255, 0, 255), this);
209 _base[p++] = new FNColorPalette(QColor(0, 255, 0), this);
210 _base[p++] = new FNColorPalette(QColor(0, 255, 255), this);
211 _base[p++] = new FNColorPalette(QColor(255, 255, 0), this);
212 _base[p++] = new FNColorPalette(QColor(255, 255, 255), this);
213 _base[p++] = new FNColorPalette(QColor(128, 128, 128), this);
214 _base[p++] = new FNColorPalette(QColor(0, 0, 128), this);
215 _base[p++] = new FNColorPalette(QColor(128, 0, 0), this);
216 _base[p++] = new FNColorPalette(QColor(128, 0, 128), this);
217 _base[p++] = new FNColorPalette(QColor(0, 128, 0), this);
218 _base[p++] = new FNColorPalette(QColor(0, 128, 128), this);
219 _base[p++] = new FNColorPalette(QColor(128, 128, 0), this);
220 _base[p++] = new FNColorPalette(QColor(200, 200, 200), this);
221
222 QGridLayout* baselayout = new QGridLayout(this, 2, 16);
223 baselayout->setMargin(0);
224 baselayout->setSpacing(0);
225 p = 0;
226 for (int i = 0; i < 2; ++i) {
227 for (int j = 0; j < 8; ++j) {
228 baselayout->addWidget(_base[p], i, j);
229 connect(_base[p], SIGNAL(clicked(FNPaletteBase*)), this, SLOT(basePaletteClicked(FNPaletteBase*)));
230 _base[p]->resize(24, 24);
231 _base[p]->setMaximumSize(24, 24);
232 _base[p]->setMinimumSize(24, 24);
233 p++;
234 }
235 }
236 mainlayout->addLayout(baselayout);
237
238 //HUE
239 _hue = new QSlider(Horizontal, this);
240 _hue->setMinValue(0);
241 _hue->setMaxValue(360);
242 _hue->setLineStep(1);
243 _hue->setPageStep(60);
244 _hue->setValue(0);
245 //sliderReleased
246 mainlayout->addWidget(_hue);
247
248 //HSVパレット
249 QHBoxLayout* hsvlayout = new QHBoxLayout(this);
250 hsvlayout->setMargin(0);
251 hsvlayout->setSpacing(2);
252 _palette = new FNHSVPalette(this);
253 _palette->setMinimumSize(90, 100);
254 hsvlayout->addWidget(_palette);
255 connect(_palette, SIGNAL(clicked(FNPaletteBase*)), this, SLOT(hsvPaletteClicked(FNPaletteBase*)));
256
257 //選択色
258 QGridLayout* selectLayout = new QGridLayout(this, 4, 4);
259 _select = new FNColorPalette(black, this);
260 _select->resize(48, 32);
261 _select->setMinimumSize(48, 32);
262 _select->setMaximumSize(32767, 32);
263 selectLayout->addMultiCellWidget(_select, 0, 0, 1, 3);
264
265 //RGBコントローラ
266 selectLayout->addWidget(new QLabel("R:", this), 1, 0);
267 _r = new QSpinBox(0, 255, 1, this);
268 _r->setValue(0);
269 selectLayout->addMultiCellWidget(_r, 1, 1, 1, 3);
270
271 selectLayout->addWidget(new QLabel("G:", this), 2, 0);
272 _g = new QSpinBox(0, 255, 1, this);
273 _g->setValue(0);
274 selectLayout->addMultiCellWidget(_g, 2, 2, 1, 3);
275
276 selectLayout->addWidget(new QLabel("B:", this), 3, 0);
277 _b = new QSpinBox(0, 255, 1, this);
278 _b->setValue(0);
279 selectLayout->addMultiCellWidget(_b, 3, 3, 1, 3);
280
281 hsvlayout->addLayout(selectLayout);
282 mainlayout->addLayout(hsvlayout);
283
284 connect(_hue, SIGNAL(valueChanged(int)), _palette, SLOT(hueChanged(int)));
285 connect(_r, SIGNAL(valueChanged(int)), this, SLOT(rgbChanged(int)));
286 connect(_g, SIGNAL(valueChanged(int)), this, SLOT(rgbChanged(int)));
287 connect(_b, SIGNAL(valueChanged(int)), this, SLOT(rgbChanged(int)));
288}
289
290FNColorDialog::~FNColorDialog()
291{
292}
293
294void FNColorDialog::rgbChanged(int)
295{
296 int r = _r->value();
297 int g = _g->value();
298 int b = _b->value();
299 setColor(QColor(r, g, b));
300}
301
302QColor FNColorDialog::color() const
303{
304 return _select->color();
305}
306void FNColorDialog::setColor(QColor c)
307{
308 if (_isblock) {
309 return;
310 }
311 _isblock = true;
312
313 int r;
314 int g;
315 int b;
316
317 c.rgb(&r, &g, &b);
318 _r->setValue(r);
319 _g->setValue(g);
320 _b->setValue(b);
321 _select->setBGColor(c);
322 _isblock = false;
323}
324
325void FNColorDialog::basePaletteClicked(FNPaletteBase* btn)
326{
327 setColor(btn->color());
328 accept();
329}
330
331void FNColorDialog::hsvPaletteClicked(FNPaletteBase* btn)
332{
333 setColor(btn->color());
334}
diff --git a/microkde/fncolordialog.h b/microkde/fncolordialog.h
new file mode 100755
index 0000000..615d2ed
--- a/dev/null
+++ b/microkde/fncolordialog.h
@@ -0,0 +1,137 @@
1/* this program for Sharp SLA300, B500, C7x0, C860 Linux PDA
2 Copyright (C) 2003-2005 Joe Kanemori.<kanemori@ymg.urban.ne.jp>
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundatibannwaon; either version 2 of the License, or
7 (at your option) any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17*/
18/*
192005/02/27 FreeNote 1.11.10pre
20・PDFの出力形式を一部変更
21・インポート時のバグfix
22
23*/
24#ifndef FNPALETTEDIALOG_H
25#define FNPALETTEDIALOG_H
26#include <qwidget.h>
27#include <qpixmap.h>
28#include <qpainter.h>
29#include <qcolor.h>
30#include <qdialog.h>
31#include <qlayout.h>
32#include <qslider.h>
33#include <qspinbox.h>
34
35//-----------------------------------------------------------------------------
36// FNPaletteBase
37//-----------------------------------------------------------------------------
38class Q_EXPORT FNPaletteBase : public QWidget
39{
40 Q_OBJECT
41public:
42
43 FNPaletteBase(QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
44
45
46 virtual ~FNPaletteBase();
47
48
49 void setBGColor(QColor c) {
50 bgcolor_ = c;
51 selection_ = c;
52 redraw();
53 };
54 QColor color() const {
55 return selection_;
56 };
57
58protected:
59 virtual void paintEvent(QPaintEvent*);
60 virtual void resizeEvent(QResizeEvent* evt);
61 virtual void redraw(bool force=false);
62 virtual void drawImpl(QPainter& pa);
63 virtual void mouseReleaseEvent(QMouseEvent* evt);
64 virtual bool pickColor(int x, int y);
65 QColor selection_;
66private:
67 QPixmap wbuf_;
68 QColor bgcolor_;
69 bool _isblock;
70
71signals:
72 void clicked(FNPaletteBase* sender);
73};
74
75
76
77
78//-----------------------------------------------------------------------------
79// FNColorPalette
80//-----------------------------------------------------------------------------
81class Q_EXPORT FNColorPalette : public FNPaletteBase
82{
83 Q_OBJECT
84public:
85 FNColorPalette(QColor c, QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
86 virtual ~FNColorPalette();
87};
88
89
90
91
92//-----------------------------------------------------------------------------
93// FNHSVPalette
94//-----------------------------------------------------------------------------
95class Q_EXPORT FNHSVPalette : public FNPaletteBase
96{
97 Q_OBJECT
98public:
99 FNHSVPalette(QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
100 virtual ~FNHSVPalette();
101public slots:
102 void hueChanged(int v);
103protected:
104 virtual void drawImpl(QPainter& pa);
105 int _hue;
106};
107
108
109
110
111//-----------------------------------------------------------------------------
112// FNColorDialog
113//-----------------------------------------------------------------------------
114class Q_EXPORT FNColorDialog : public QDialog
115{
116 Q_OBJECT
117public:
118 FNColorDialog(QWidget* parent=0, const char* name=0, WFlags f=0);
119 virtual ~FNColorDialog();
120 void setColor(QColor c);
121 QColor color() const;
122public slots:
123 virtual void basePaletteClicked(FNPaletteBase*);
124 virtual void hsvPaletteClicked(FNPaletteBase*);
125 void rgbChanged(int);
126private:
127 FNHSVPalette* _palette;
128 FNColorPalette* _base[16];
129 QSlider* _hue;
130 FNColorPalette* _select;
131 QSpinBox* _r;
132 QSpinBox* _g;
133 QSpinBox* _b;
134 bool _isblock;
135
136};
137#endif //FNPALETTEDIALOG_H
diff --git a/microkde/kcolordialog.cpp b/microkde/kcolordialog.cpp
index a3d8973..b9bb5bb 100644
--- a/microkde/kcolordialog.cpp
+++ b/microkde/kcolordialog.cpp
@@ -10,84 +10,10 @@
10#include <kglobal.h> 10#include <kglobal.h>
11QColor KColorDialog::getColor( ) const 11QColor KColorDialog::getColor( ) const
12{ 12{
13 QColor c ( r->value(), g->value(), b->value() ); 13 return color();
14 lar->setText ( "R: " + QString::number ( c.red() ) );
15 lag->setText ( "G: " + QString::number ( c.green() ) );
16 lab->setText ( "B: " + QString::number ( c.blue() ) );
17 return c;
18} 14}
19void KColorDialog::setColor( const QColor & d )
20{
21 r->setValue(d.red() );
22 g->setValue(d.green() );
23 b->setValue(d.blue() );
24 old_color->setPalette( QPalette( d.dark(), d ) );
25 lar->setText ( "R: " + QString::number ( d.red() ) );
26 lag->setText ( "G: " + QString::number ( d.green() ) );
27 lab->setText ( "B: " + QString::number ( d.blue() ) );
28
29}
30KColorDialog::KColorDialog( QWidget *p ):QDialog( p, "input-dialog", true )
31{
32 setCaption( i18n("Choose Color") );
33
34 setMaximumSize( QApplication::desktop()->width() - 20, QApplication::desktop()->height() - 40 ); // for zaurus 5500er.
35 QGridLayout* lay = new QGridLayout ( this, 4, 2 );
36 lay->setSpacing( 6 );
37 lay->setMargin( 11 );
38
39 old_color = new QLabel("Old color",this);
40 old_color->setFrameStyle( QFrame::Panel | QFrame::Plain );
41 old_color->setLineWidth( 1 );
42 lay->addWidget(old_color, 0, 0);
43
44 new_color = new QLabel("New color", this);
45 new_color->setFrameStyle( QFrame::Panel | QFrame::Plain );
46 new_color->setLineWidth( 1 );
47 lay->addWidget(new_color, 0, 1);
48 new_color->setAlignment( AlignCenter );
49 15
50 QHBox* hb = new QHBox ( this ); 16KColorDialog::KColorDialog( QWidget *p ):FNColorDialog( p, "input-dialog" )
51 lar = new QLabel( hb );
52 lag = new QLabel( hb );
53 lab = new QLabel( hb );
54 lay->addMultiCellWidget( hb,1,1, 0,1 );
55
56 QLabel* lr = new QLabel ( "Red:", this );
57 lay->addWidget( lr,2,0 );
58 r = new QSlider ( 0, 255, 1, 1, Horizontal, this );
59 lay->addWidget(r ,2,1 );
60
61 QLabel* lg = new QLabel( "Green:",this );
62 lay->addWidget(lg ,3,0 );
63 g = new QSlider ( 0, 255, 1, 1, Horizontal, this );
64 lay->addWidget( g ,3,1 );
65
66 QLabel* lb = new QLabel ( "Blue:",this );
67 lay->addWidget( lb,4,0 );
68 b = new QSlider ( 0, 255, 1, 1, Horizontal, this );
69 lay->addWidget(b ,4,1 );
70
71 QColor d = backgroundColor();
72 r->setValue(d.red() );
73 g->setValue(d.green() );
74 b->setValue(d.blue() );
75 old_color->setPalette( QPalette( d.dark() , d ) );
76 // kannst du wieder reinnehmen, aber es geht auch so.
77 QPushButton * ok = new QPushButton (i18n(" OK "), this );
78 ok->setDefault( true );
79 QPushButton * cancel = new QPushButton (i18n(" Cancel "), this );
80
81 lay->addWidget(ok ,5,0 );
82 lay->addWidget(cancel ,5,1 );
83 connect (ok, SIGNAL( clicked() ), this ,SLOT (accept() ));
84 connect (cancel, SIGNAL( clicked() ), this ,SLOT (reject() ));
85 connect (r, SIGNAL( valueChanged ( int ) ), this ,SLOT (updateColor( int ) ));
86 connect (g, SIGNAL( valueChanged ( int ) ), this ,SLOT (updateColor( int ) ));
87 connect (b, SIGNAL( valueChanged ( int ) ), this ,SLOT (updateColor( int ) ));
88}
89void KColorDialog::updateColor( int )
90{ 17{
91 QColor c = getColor( ) ; 18
92 new_color->setPalette( QPalette( c.dark(), c ) );
93} 19}
diff --git a/microkde/kcolordialog.h b/microkde/kcolordialog.h
index bb2045d..0858352 100644
--- a/microkde/kcolordialog.h
+++ b/microkde/kcolordialog.h
@@ -6,19 +6,14 @@
6#include <qdialog.h> 6#include <qdialog.h>
7#include <qslider.h> 7#include <qslider.h>
8#include <qlabel.h> 8#include <qlabel.h>
9class KColorDialog : public QDialog 9#include <fncolordialog.h>
10
11class KColorDialog : public FNColorDialog
10{ 12{
11Q_OBJECT 13Q_OBJECT
12 public: 14 public:
13 KColorDialog( QWidget *p ); 15 KColorDialog( QWidget *p );
14 QColor getColor( ) const; 16 QColor getColor( ) const;
15 void setColor( const QColor &);
16 private:
17 QSlider *r, *g, *b;
18 QLabel * old_color, *new_color;
19 QLabel *lar, *lag, *lab;
20private slots:
21 void updateColor( int );
22}; 17};
23 18
24 19
diff --git a/microkde/microkdeE.pro b/microkde/microkdeE.pro
index c54fb22..335fcd0 100644
--- a/microkde/microkdeE.pro
+++ b/microkde/microkdeE.pro
@@ -16,7 +16,7 @@ DESTDIR=$(QPEDIR)/lib
16INTERFACES = \ 16INTERFACES = \
17 17
18HEADERS = \ 18HEADERS = \
19qlayoutengine_p.h \ 19qlayoutengine_p.h fncolordialog.h\
20KDGanttMinimizeSplitter.h \ 20KDGanttMinimizeSplitter.h \
21 kapplication.h \ 21 kapplication.h \
22 kaudioplayer.h \ 22 kaudioplayer.h \
@@ -104,7 +104,7 @@ KDGanttMinimizeSplitter.h \
104 104
105 105
106SOURCES = \ 106SOURCES = \
107KDGanttMinimizeSplitter.cpp \ 107KDGanttMinimizeSplitter.cpp fncolordialog.cpp \
108 kapplication.cpp \ 108 kapplication.cpp \
109 kcalendarsystem.cpp \ 109 kcalendarsystem.cpp \
110 kcalendarsystemgregorian.cpp \ 110 kcalendarsystemgregorian.cpp \