summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-01-15 13:59:58 (UTC)
committer mickeyl <mickeyl>2004-01-15 13:59:58 (UTC)
commitdde789ef19fa3a3913805e452ac1e3400688e8a0 (patch) (unidiff)
treea33a0ce31750ad56cfd3362585d4e7b32ca0a456
parent3c74c5343a8432c494ace71d94cca354c01ef1d3 (diff)
downloadopie-dde789ef19fa3a3913805e452ac1e3400688e8a0.zip
opie-dde789ef19fa3a3913805e452ac1e3400688e8a0.tar.gz
opie-dde789ef19fa3a3913805e452ac1e3400688e8a0.tar.bz2
more libopie1 --> libopie2 with namespace cleanups and code layout cleanups
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp222
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.h109
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp1094
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h161
-rw-r--r--libopie2/opieui/fileselector/ofileselector_p.h191
-rw-r--r--libopie2/opieui/fileselector/ofileview.h95
-rw-r--r--libopie2/opieui/ocheckitem.cpp127
-rw-r--r--libopie2/opieui/ocheckitem.h86
-rw-r--r--libopie2/opieui/oclickablelabel.cpp173
-rw-r--r--libopie2/opieui/oclickablelabel.h103
-rw-r--r--libopie2/opieui/opieui.pro18
-rw-r--r--libqtaux/libqtaux.pro6
-rw-r--r--libqtaux/ocolorbutton.cpp150
-rw-r--r--libqtaux/ocolorbutton.h80
-rw-r--r--libqtaux/ocolorpopupmenu.cpp3
-rw-r--r--libqtaux/ocolorpopupmenu.h11
16 files changed, 2621 insertions, 8 deletions
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp
new file mode 100644
index 0000000..2a89c5d
--- a/dev/null
+++ b/libopie2/opieui/fileselector/ofiledialog.cpp
@@ -0,0 +1,222 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29
30/* OPIE */
31#include <opie2/ofiledialog.h>
32#include <qpe/applnk.h>
33#include <qpe/config.h>
34#include <qpe/qpeapplication.h>
35
36/* QT */
37#include <qfileinfo.h>
38#include <qstring.h>
39#include <qapplication.h>
40#include <qlayout.h>
41
42using namespace Opie;
43
44namespace
45{
46/*
47 * helper functions to load the start dir
48 * and to save it
49 * helper to extract the dir out of a file name
50 */
51/**
52 * This method will use Config( argv[0] );
53 * @param key The group key used
54 */
55QString lastUsedDir( const QString& key )
56{
57 if ( qApp->argc() < 1 )
58 return QString::null;
59
60 Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
61 cfg.setGroup( key );
62 return cfg.readEntry("LastDir", QPEApplication::documentDir() );
63}
64
65void saveLastDir( const QString& key, const QString& file )
66{
67 if ( qApp->argc() < 1 )
68 return;
69
70 Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
71 cfg.setGroup( key );
72 QFileInfo inf( file );
73 cfg.writeEntry("LastDir", inf.dirPath( true ) );
74}
75};
76
77/**
78 * This constructs a modal dialog
79 *
80 * @param caption The caption of the dialog
81 * @param wid The parent widget
82 * @param mode The mode of the OFileSelector @see OFileSelector
83 * @param selector The selector of the OFileSelector
84 * @param dirName the dir or resource to start from
85 * @param fileName a proposed or existing filename
86 * @param mimetypes The mimeTypes
87 */
88OFileDialog::OFileDialog(const QString &caption,
89 QWidget *wid, int mode, int selector,
90 const QString &dirName,
91 const QString &fileName,
92 const QMap<QString,QStringList>& mimetypes )
93 : QDialog( wid, "OFileDialog", true )
94{
95 // QVBoxLayout *lay = new QVBoxLayout(this);
96 //showMaximized();
97 QVBoxLayout *lay = new QVBoxLayout(this );
98 file = new OFileSelector(this , mode, selector,
99 dirName, fileName,
100 mimetypes );
101 lay->addWidget( file );
102
103 //lay->addWidget( file );
104 //showFullScreen();
105 setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
106 connect(file, SIGNAL(fileSelected(const QString&) ),
107 this, SLOT(slotFileSelected(const QString&) ) );
108 connect(file, SIGNAL(ok() ),
109 this, SLOT(slotSelectorOk()) ) ;
110
111 connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
112
113#if 0
114 connect(file, SIGNAL(dirSelected(const QString &) ),
115 this, SLOT(slotDirSelected(const QString &) ) );
116#endif
117}
118/**
119 * @returns the mimetype of the selected
120 * currently it return QString::null
121 */
122QString OFileDialog::mimetype()const
123{
124 return QString::null;
125}
126
127/**
128 * @return the fileName
129 */
130QString OFileDialog::fileName()const
131{
132 return file->selectedName();
133}
134
135/**
136 * return a DocLnk to the current file
137 */
138DocLnk OFileDialog::selectedDocument()const
139{
140 return file->selectedDocument();
141}
142
143/**
144 * This opens up a filedialog in Open mode
145 *
146 * @param selector the Selector Mode
147 * @param startDir Where to start from
148 * @param file A proposed filename
149 * @param mimes A list of MimeTypes
150 * @param wid the parent
151 * @param caption of the dialog if QString::null tr("Open") will be used
152 * @return the fileName or QString::null
153 */
154QString OFileDialog::getOpenFileName(int selector,
155 const QString &_startDir,
156 const QString &file,
157 const MimeTypes &mimes,
158 QWidget *wid,
159 const QString &caption )
160{
161 QString ret;
162 QString startDir = _startDir;
163 if (startDir.isEmpty() )
164 startDir = lastUsedDir( "FileDialog-OPEN" );
165
166
167 OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
168 wid, OFileSelector::Open, selector, startDir, file, mimes);
169 dlg.showMaximized();
170 if( dlg.exec() )
171 {
172 ret = dlg.fileName();
173 saveLastDir( "FileDialog-OPEN", ret );
174 }
175
176 return ret;
177}
178
179/**
180 * This opens up a file dialog in save mode
181 * @see getOpenFileName
182 */
183QString OFileDialog::getSaveFileName(int selector,
184 const QString &_startDir,
185 const QString &file,
186 const MimeTypes &mimes,
187 QWidget *wid,
188 const QString &caption )
189{
190 QString ret;
191 QString startDir = _startDir;
192 if (startDir.isEmpty() )
193 startDir = lastUsedDir( "FileDialog-SAVE" );
194
195 OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
196 wid, OFileSelector::Save, selector, startDir, file, mimes);
197 dlg.showMaximized();
198 if( dlg.exec() )
199 {
200 ret = dlg.fileName();
201 saveLastDir( "FileDialog-SAVE", ret );
202 }
203
204 return ret;
205}
206
207void OFileDialog::slotFileSelected(const QString & )
208{
209 accept();
210}
211
212void OFileDialog::slotSelectorOk( )
213{
214 accept();
215}
216
217void OFileDialog::slotDirSelected(const QString &dir )
218{
219 setCaption( dir );
220 // if mode
221 //accept();
222}
diff --git a/libopie2/opieui/fileselector/ofiledialog.h b/libopie2/opieui/fileselector/ofiledialog.h
new file mode 100644
index 0000000..01a599b
--- a/dev/null
+++ b/libopie2/opieui/fileselector/ofiledialog.h
@@ -0,0 +1,109 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (c) 2002 zecke <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef OFILEDIALOG_H
30#define OFILEDIALOG_H
31
32/* OPIE */
33#include <opie2/ofileselector.h>
34
35/* QT */
36#include <qdialog.h>
37
38namespace Opie
39{
40
41/**
42 * This class places a OFileSelector inside a QDialog.
43 * It provides static method for letting a user chose
44 * a file for either opening or saving.
45 * Most of the time the c'tor will not be used instead using
46 * the static member functions is prefered.
47 *
48 * <pre>
49 * QMap<QString, QStringList> mimeTypes;
50 * QStringList types;
51 * types << "text[slash]* ";
52 * mimeTypes.insert( tr("Text"), types );
53 * mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment
54 * QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
55 * "foo","bar", mimeTypes);
56 * </pre>
57 *
58 * @short A small QDialog swalloing a FileSelector
59 * @see QDialog
60 * @see OFileSelector
61 * @version 0.1-unfinished
62 * @author Holger Freyther ( zecke@handhelds.org )
63 */
64class OFileDialog : public QDialog
65{
66 Q_OBJECT
67public:
68 OFileDialog(const QString &caption,
69 QWidget *, int mode, int selector,
70 const QString &dirName,
71 const QString &fileName = QString::null,
72 const MimeTypes &mimetypes = MimeTypes() );
73 QString mimetype() const;
74 QString fileName() const;
75 DocLnk selectedDocument()const;
76
77 // static methods
78 static QString getOpenFileName(int selector,
79 const QString& startDir = QString::null,
80 const QString &fileName = QString::null,
81 const MimeTypes& mime = MimeTypes(),
82 QWidget *wid = 0,
83 const QString &caption = QString::null );
84
85 static QString getSaveFileName(int selector,
86 const QString& startDir = QString::null,
87 const QString& fileName = QString::null,
88 const MimeTypes& mimefilter = MimeTypes(),
89 QWidget *wid = 0,
90 const QString &caption = QString::null );
91
92 //let's OFileSelector catch up first
93 //static QString getExistingDirectory(const QString& startDir = QString::null,
94 //QWidget *parent = 0, const QString& caption = QString::null );
95
96private:
97 class OFileDialogPrivate;
98 OFileDialogPrivate *d;
99 OFileSelector *file;
100
101private slots:
102 void slotFileSelected( const QString & );
103 void slotDirSelected(const QString & );
104 void slotSelectorOk();
105};
106
107};
108
109#endif
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
new file mode 100644
index 0000000..71d765c
--- a/dev/null
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -0,0 +1,1094 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29/* hacky but we need to get FileSelector::filter */
30#define private public
31#include <qpe/fileselector.h>
32#undef private
33
34#include "ofileselector_p.h"
35
36/* OPIE */
37#include <opie2/ofileselector.h>
38
39#include <qpe/qpeapplication.h>
40#include <qpe/mimetype.h>
41#include <qpe/resource.h>
42#include <qpe/storage.h>
43
44/* QT */
45#include <qcombobox.h>
46#include <qdir.h>
47#include <qhbox.h>
48#include <qheader.h>
49#include <qlabel.h>
50#include <qlayout.h>
51#include <qlineedit.h>
52#include <qlistview.h>
53#include <qpopupmenu.h>
54#include <qwidgetstack.h>
55#include <qregexp.h>
56#include <qobjectlist.h>
57
58using namespace Opie;
59
60OFileViewInterface::OFileViewInterface( OFileSelector* selector )
61 : m_selector( selector )
62{}
63
64OFileViewInterface::~OFileViewInterface()
65{}
66
67QString OFileViewInterface::name()const
68{
69 return m_name;
70}
71
72void OFileViewInterface::setName( const QString& name )
73{
74 m_name = name;
75}
76
77OFileSelector* OFileViewInterface::selector()const
78{
79 return m_selector;
80}
81
82DocLnk OFileViewInterface::selectedDocument()const
83{
84 return DocLnk( selectedName() );
85}
86
87bool OFileViewInterface::showNew()const
88{
89 return selector()->showNew();
90}
91
92bool OFileViewInterface::showClose()const
93{
94 return selector()->showClose();
95}
96
97MimeTypes OFileViewInterface::mimeTypes()const
98{
99 return selector()->mimeTypes();
100}
101
102QStringList OFileViewInterface::currentMimeType()const
103{
104 return selector()->currentMimeType();
105}
106
107void OFileViewInterface::activate( const QString& )
108{
109 // not implemented here
110}
111
112void OFileViewInterface::ok()
113{
114 emit selector()->ok();
115}
116
117void OFileViewInterface::cancel()
118{
119 emit selector()->cancel();
120}
121
122void OFileViewInterface::closeMe()
123{
124 emit selector()->closeMe();
125}
126
127void OFileViewInterface::fileSelected( const QString& str)
128{
129 emit selector()->fileSelected( str);
130}
131
132void OFileViewInterface::fileSelected( const DocLnk& lnk)
133{
134 emit selector()->fileSelected( lnk );
135}
136
137void OFileViewInterface::setCurrentFileName( const QString& str )
138{
139 selector()->m_lneEdit->setText( str );
140}
141
142QString OFileViewInterface::currentFileName()const
143{
144 return selector()->m_lneEdit->text();
145}
146
147QString OFileViewInterface::startDirectory()const
148{
149 return selector()->m_startDir;
150}
151
152ODocumentFileView::ODocumentFileView( OFileSelector* selector )
153 :OFileViewInterface( selector )
154{
155 m_selector = 0;
156 setName( QObject::tr("Documents") );
157}
158
159ODocumentFileView::~ODocumentFileView()
160{
161}
162
163QString ODocumentFileView::selectedName()const
164{
165 if (!m_selector)
166 return QString::null;
167
168 return m_selector->selectedDocument().file();
169}
170
171QString ODocumentFileView::selectedPath()const
172{
173 return QPEApplication::documentDir();
174}
175
176QString ODocumentFileView::directory()const
177{
178 return selectedPath();
179}
180
181void ODocumentFileView::reread()
182{
183 if (!m_selector)
184 return;
185
186 m_selector->setNewVisible( showNew() );
187 m_selector->setCloseVisible( showClose() );
188 m_selector->filter = currentMimeType().join(";");
189 m_selector->reread();
190}
191
192int ODocumentFileView::fileCount()const
193{
194 if (!m_selector)
195 return -1;
196
197 return m_selector->fileCount();
198}
199
200DocLnk ODocumentFileView::selectedDocument()const
201{
202 if (!m_selector)
203 return DocLnk();
204
205 return m_selector->selectedDocument();
206}
207
208QWidget* ODocumentFileView::widget( QWidget* parent )
209{
210 if (!m_selector )
211 {
212 m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() );
213 QObject::connect(m_selector, SIGNAL(fileSelected( const DocLnk& ) ),
214 selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) );
215 QObject::connect(m_selector, SIGNAL(closeMe() ),
216 selector(), SIGNAL(closeMe() ) );
217 QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk& ) ),
218 selector(), SIGNAL(newSelected(const DocLnk& ) ) );
219 }
220
221 return m_selector;
222}
223
224/*
225 * This is the file system view used
226 * we use a QListView + QListViewItems for it
227 */
228
229OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
230 const QString& path, const QString& date,
231 const QString& size, const QString& dir,
232 bool isLocked, bool isDir )
233 : QListViewItem( view )
234{
235 setPixmap(0, pixmap );
236 setText(1, path );
237 setText(2, size );
238 setText(3, date );
239 m_isDir = isDir;
240 m_dir = dir;
241 m_locked = isLocked;
242}
243
244OFileSelectorItem::~OFileSelectorItem()
245{
246}
247
248bool OFileSelectorItem::isLocked()const
249{
250 return m_locked;
251}
252
253QString OFileSelectorItem::directory()const
254{
255 return m_dir;
256}
257
258bool OFileSelectorItem::isDir()const
259{
260 return m_isDir;
261}
262
263QString OFileSelectorItem::path()const
264{
265 return text( 1 );
266}
267
268QString OFileSelectorItem::key( int id, bool )const
269{
270 QString ke;
271 if( id == 0 || id == 1 )
272 { // name
273 if( m_isDir )
274 {
275 ke.append("0" );
276 ke.append( text(1) );
277 }
278 else
279 {
280 ke.append("1" );
281 ke.append( text(1) );
282 }
283 return ke;
284 }
285 else
286 return text( id );
287
288}
289
290OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel)
291 :QWidget( parent ), m_sel( sel )
292{
293 m_all = false;
294 QVBoxLayout* lay = new QVBoxLayout( this );
295 m_currentDir = startDir;
296
297 /*
298 * now we add a special bar
299 * One Button For Up
300 * Home
301 * Doc
302 * And a dropdown menu with FileSystems
303 * FUTURE: one to change dir with lineedit
304 * Bookmarks
305 * Create Dir
306 */
307 QHBox* box = new QHBox(this );
308 box->setBackgroundMode( PaletteButton );
309 box->setSpacing( 0 );
310
311 QToolButton *btn = new QToolButton( box );
312 btn->setIconSet( Resource::loadIconSet("up") );
313 connect(btn, SIGNAL(clicked() ),
314 this, SLOT( cdUP() ) );
315
316 btn = new QToolButton( box );
317 btn->setIconSet( Resource::loadIconSet("home") );
318 connect(btn, SIGNAL(clicked() ),
319 this, SLOT( cdHome() ) );
320
321 btn = new QToolButton( box );
322 btn->setIconSet( Resource::loadIconSet("DocsIcon") );
323 connect(btn, SIGNAL(clicked() ),
324 this, SLOT(cdDoc() ) );
325
326 m_btnNew = new QToolButton( box );
327 m_btnNew->setIconSet( Resource::loadIconSet("new") );
328 connect(m_btnNew, SIGNAL(clicked() ),
329 this, SLOT(slotNew() ) );
330
331
332 m_btnClose = new QToolButton( box );
333 m_btnClose->setIconSet( Resource::loadIconSet("close") );
334 connect(m_btnClose, SIGNAL(clicked() ),
335 selector(), SIGNAL(closeMe() ) );
336
337 btn = new QToolButton( box );
338 btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
339
340 /* let's fill device parts */
341 QPopupMenu* pop = new QPopupMenu(this);
342 connect(pop, SIGNAL( activated(int) ),
343 this, SLOT(slotFSActivated(int) ) );
344
345 StorageInfo storage;
346 const QList<FileSystem> &fs = storage.fileSystems();
347 QListIterator<FileSystem> it(fs);
348 for ( ; it.current(); ++it )
349 {
350 const QString disk = (*it)->name();
351 const QString path = (*it)->path();
352 m_dev.insert( disk, path );
353 pop->insertItem( disk );
354 }
355 m_fsPop = pop;
356
357
358 btn->setPopup( pop );
359
360 lay->addWidget( box );
361
362 m_view = new QListView( this );
363
364 m_view->installEventFilter(this);
365
366 QPEApplication::setStylusOperation( m_view->viewport(),
367 QPEApplication::RightOnHold);
368 m_view->addColumn(" " );
369 m_view->addColumn(tr("Name"), 135 );
370 m_view->addColumn(tr("Size"), -1 );
371 m_view->addColumn(tr("Date"), 60 );
372 m_view->addColumn(tr("Mime Type"), -1 );
373
374
375 m_view->setSorting( 1 );
376 m_view->setAllColumnsShowFocus( TRUE );
377
378 lay->addWidget( m_view, 1000 );
379 connectSlots();
380}
381
382OFileViewFileListView::~OFileViewFileListView()
383{
384}
385
386void OFileViewFileListView::slotNew()
387{
388 DocLnk lnk;
389 emit selector()->newSelected( lnk );
390}
391
392OFileSelectorItem* OFileViewFileListView::currentItem()const
393{
394 QListViewItem* item = m_view->currentItem();
395 if (!item )
396 return 0l;
397
398 return static_cast<OFileSelectorItem*>(item);
399}
400
401void OFileViewFileListView::reread( bool all )
402{
403 m_view->clear();
404
405 if (selector()->showClose() )
406 m_btnClose->show();
407 else
408 m_btnClose->hide();
409
410 if (selector()->showNew() )
411 m_btnNew->show();
412 else
413 m_btnNew->hide();
414
415 m_mimes = selector()->currentMimeType();
416 m_all = all;
417
418 QDir dir( m_currentDir );
419 if (!dir.exists() )
420 return;
421
422 dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
423 int filter;
424 if (m_all )
425 filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
426 else
427 filter = QDir::Files | QDir::Dirs | QDir::All;
428 dir.setFilter( filter );
429
430 // now go through all files
431 const QFileInfoList *list = dir.entryInfoList();
432 if (!list)
433 {
434 cdUP();
435 return;
436 }
437
438 QFileInfoListIterator it( *list );
439 QFileInfo *fi;
440 while( (fi=it.current() ) )
441 {
442 if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") )
443 {
444 ++it;
445 continue;
446 }
447
448 /*
449 * It is a symlink we try to resolve it now but don't let us attack by DOS
450 *
451 */
452 if( fi->isSymLink() )
453 {
454 QString file = fi->dirPath( true ) + "/" + fi->readLink();
455 for( int i = 0; i<=4; i++)
456 { // 5 tries to prevent dos
457 QFileInfo info( file );
458 if( !info.exists() )
459 {
460 addSymlink( fi, TRUE );
461 break;
462 }
463 else if( info.isDir() )
464 {
465 addDir( fi, TRUE );
466 break;
467 }
468 else if( info.isFile() )
469 {
470 addFile( fi, TRUE );
471 break;
472 }
473 else if( info.isSymLink() )
474 {
475 file = info.dirPath(true ) + "/" + info.readLink() ;
476 break;
477 }
478 else if( i == 4)
479 { // couldn't resolve symlink add it as symlink
480 addSymlink( fi );
481 }
482 } // off for loop for symlink resolving
483 }
484 else if( fi->isDir() )
485 addDir( fi );
486 else if( fi->isFile() )
487 addFile( fi );
488
489 ++it;
490 } // of while loop
491 m_view->sort();
492
493}
494int OFileViewFileListView::fileCount()const
495{
496 return m_view->childCount();
497}
498
499QString OFileViewFileListView::currentDir()const
500{
501 return m_currentDir;
502}
503
504OFileSelector* OFileViewFileListView::selector()
505{
506 return m_sel;
507}
508
509bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e)
510{
511 if ( e->type() == QEvent::KeyPress )
512 {
513 QKeyEvent *k = (QKeyEvent *)e;
514 if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
515 {
516 slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
517 return true;
518 }
519 }
520 return false;
521}
522
523void OFileViewFileListView::connectSlots()
524{
525 connect(m_view, SIGNAL(clicked(QListViewItem*) ),
526 this, SLOT(slotCurrentChanged(QListViewItem*) ) );
527 connect(m_view, SIGNAL(mouseButtonClicked(int, QListViewItem*, const QPoint&, int ) ),
528 this, SLOT(slotClicked(int, QListViewItem*, const QPoint&, int ) ) );
529}
530
531void OFileViewFileListView::slotCurrentChanged( QListViewItem* item)
532{
533 if (!item)
534 return;
535#if 0
536
537 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
538
539 if (!sel->isDir() )
540 {
541 selector()->m_lneEdit->setText( sel->text(1) );
542 // if in fileselector mode we will emit selected
543 if ( selector()->mode() == OFileSelector::FileSelector )
544 {
545 qWarning("slot Current Changed");
546 QStringList str = QStringList::split("->", sel->text(1) );
547 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
548 emit selector()->fileSelected( path );
549 DocLnk lnk( path );
550 emit selector()->fileSelected( lnk );
551 }
552 }
553#endif
554}
555
556void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int )
557{
558 if (!item || ( button != Qt::LeftButton) )
559 return;
560
561 OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
562 if (!sel->isLocked() )
563 {
564 QStringList str = QStringList::split("->", sel->text(1) );
565 if (sel->isDir() )
566 {
567 m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
568 emit selector()->dirSelected( m_currentDir );
569 reread( m_all );
570 }
571 else
572 { // file
573 qWarning("slot Clicked");
574 selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
575 QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
576 emit selector()->fileSelected( path );
577 DocLnk lnk( path );
578 emit selector()->fileSelected( lnk );
579 }
580 } // not locked
581}
582
583void OFileViewFileListView::addFile( QFileInfo* info, bool symlink )
584{
585 MimeType type( info->absFilePath() );
586 if (!compliesMime( type.id() ) )
587 return;
588
589 QPixmap pix = type.pixmap();
590 QString dir, name; bool locked;
591 if ( pix.isNull() )
592 {
593 QWMatrix matrix;
594 QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
595 matrix.scale( .4, .4 );
596 pix = pixer.xForm( matrix );
597 }
598 dir = info->dirPath( true );
599 locked = false;
600 if ( symlink )
601 name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
602 else
603 {
604 name = info->fileName();
605 if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
606 ( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) )
607 {
608 locked = true; pix = Resource::loadPixmap("locked");
609 }
610 }
611 (void)new OFileSelectorItem( m_view, pix, name,
612 info->lastModified().toString(), QString::number( info->size() ),
613 dir, locked );
614}
615
616void OFileViewFileListView::addDir( QFileInfo* info, bool symlink )
617{
618 bool locked = false; QString name; QPixmap pix;
619
620 if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
621 ( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) )
622 {
623 locked = true;
624 if ( symlink )
625 pix = Resource::loadPixmap( "opie/symlink" );
626 else
627 pix = Resource::loadPixmap( "lockedfolder" );
628 }
629 else
630 pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
631
632 name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
633 info->fileName();
634
635 (void)new OFileSelectorItem( m_view, pix, name,
636 info->lastModified().toString(),
637 QString::number( info->size() ),
638 info->dirPath( true ), locked, true );
639
640
641}
642
643void OFileViewFileListView::addSymlink( QFileInfo* , bool )
644{
645}
646
647void OFileViewFileListView::cdUP()
648{
649 QDir dir( m_currentDir );
650 dir.cdUp();
651
652 if (!dir.exists() )
653 m_currentDir = "/";
654 else
655 m_currentDir = dir.absPath();
656
657 emit selector()->dirSelected( m_currentDir );
658 reread( m_all );
659}
660
661void OFileViewFileListView::cdHome()
662{
663 m_currentDir = QDir::homeDirPath();
664 emit selector()->dirSelected( m_currentDir );
665 reread( m_all );
666}
667
668void OFileViewFileListView::cdDoc()
669{
670 m_currentDir = QPEApplication::documentDir();
671 emit selector()->dirSelected( m_currentDir );
672 reread( m_all );
673}
674
675void OFileViewFileListView::changeDir( const QString& dir )
676{
677 m_currentDir = dir;
678 emit selector()->dirSelected( m_currentDir );
679 reread( m_all );
680}
681
682void OFileViewFileListView::slotFSActivated( int id )
683{
684 changeDir ( m_dev[m_fsPop->text(id)] );
685}
686
687/* check if the mimetype in mime
688 * complies with the one which is current
689 */
690/*
691 * We've the mimetype of the file
692 * We need to get the stringlist of the current mimetype
693 *
694 * mime = image@slashjpeg
695 * QStringList = 'image@slash*'
696 * or QStringList = image/jpeg;image/png;application/x-ogg
697 * or QStringList = application/x-ogg;image@slash*;
698 * with all these mime filters it should get acceptes
699 * to do so we need to look if mime is contained inside
700 * the stringlist
701 * if it's contained return true
702 * if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
703 * is contained in the mimefilter and then we will
704 * look if both are equal until the '/'
705 */
706
707bool OFileViewFileListView::compliesMime( const QString& str)
708{
709 if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
710 return true;
711
712 for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it )
713 {
714 QRegExp reg( (*it) );
715 reg.setWildcard( true );
716 if ( str.find( reg ) != -1 )
717 return true;
718
719 }
720 return false;
721}
722/*
723 * The listView giving access to the file system!
724 */
725
726class OFileViewFileSystem : public OFileViewInterface
727{
728public:
729 OFileViewFileSystem( OFileSelector* );
730 ~OFileViewFileSystem();
731
732 QString selectedName() const;
733 QString selectedPath() const;
734
735 QString directory()const;
736 void reread();
737 int fileCount()const;
738
739 QWidget* widget( QWidget* parent );
740 void activate( const QString& );
741private:
742 OFileViewFileListView* m_view;
743 bool m_all : 1;
744};
745
746OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
747 : OFileViewInterface( sel )
748{
749 m_view = 0;
750 m_all = false;
751}
752
753OFileViewFileSystem::~OFileViewFileSystem()
754{
755}
756
757QString OFileViewFileSystem::selectedName()const
758{
759 if (!m_view )
760 return QString::null;
761
762 QString cFN=currentFileName();
763 if (cFN.startsWith("/")) return cFN;
764 return m_view->currentDir() + "/" + cFN;
765}
766
767QString OFileViewFileSystem::selectedPath()const
768{
769 return QString::null;
770}
771
772QString OFileViewFileSystem::directory()const
773{
774 if (!m_view)
775 return QString::null;
776
777 OFileSelectorItem* item = m_view->currentItem();
778 if (!item )
779 return QString::null;
780
781 return QDir(item->directory() ).absPath();
782}
783
784void OFileViewFileSystem::reread()
785{
786 if (!m_view)
787 return;
788
789 m_view->reread( m_all );
790}
791
792int OFileViewFileSystem::fileCount()const
793{
794 if (!m_view )
795 return -1;
796 return m_view->fileCount();
797}
798
799QWidget* OFileViewFileSystem::widget( QWidget* parent )
800{
801 if (!m_view )
802 {
803 m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
804 }
805 return m_view;
806}
807
808void OFileViewFileSystem::activate( const QString& str)
809{
810 m_all = (str != QObject::tr("Files") );
811}
812
813/* Selector */
814OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
815 const QString& dirName, const QString& fileName,
816 const MimeTypes& mimetypes,
817 bool showNew, bool showClose)
818 :QWidget( parent, "OFileSelector" )
819{
820 m_current = 0;
821 m_shNew = showNew;
822 m_shClose = showClose;
823 m_mimeType = mimetypes;
824 m_startDir = dirName;
825
826 m_mode = mode;
827 m_selector = sel;
828
829 initUI();
830 m_lneEdit->setText( fileName );
831 initMime();
832 initViews();
833
834 QString str;
835 switch ( m_selector )
836 {
837 default:
838 case Normal:
839 str = QObject::tr("Documents");
840 m_cmbView->setCurrentItem( 0 );
841 break;
842 case Extended:
843 str = QObject::tr("Files");
844 m_cmbView->setCurrentItem( 1 );
845 break;
846 case ExtendedAll:
847 str = QObject::tr("All Files");
848 m_cmbView->setCurrentItem( 2 );
849 break;
850 }
851 slotViewChange( str );
852
853}
854
855OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
856 bool showNew, bool showClose )
857 : QWidget( parent, name )
858{
859 m_current = 0;
860 m_shNew = showNew;
861 m_shClose = showClose;
862 m_startDir = QPEApplication::documentDir();
863
864 if (!mimeFilter.isEmpty() )
865 m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
866
867 m_mode = OFileSelector::FileSelector;
868 m_selector = OFileSelector::Normal;
869
870 initUI();
871 initMime();
872 initViews();
873 m_cmbView->setCurrentItem( 0 );
874 slotViewChange( QObject::tr("Documents") );
875}
876
877/*
878 * INIT UI will set up the basic GUI
879 * Layout: Simple VBoxLayout
880 * On top a WidgetStack containing the Views...
881 * - List View
882 * - Document View
883 * Below we will have a Label + LineEdit
884 * Below we will have two ComoBoxes one for choosing the view one for
885 * choosing the mimetype
886 */
887void OFileSelector::initUI()
888{
889 QVBoxLayout* lay = new QVBoxLayout( this );
890
891 m_stack = new QWidgetStack( this );
892 lay->addWidget( m_stack, 1000 );
893
894 m_nameBox = new QHBox( this );
895 (void)new QLabel( tr("Name:"), m_nameBox );
896 m_lneEdit = new QLineEdit( m_nameBox );
897 m_lneEdit ->installEventFilter(this);
898 lay->addWidget( m_nameBox );
899
900 m_cmbBox = new QHBox( this );
901 m_cmbView = new QComboBox( m_cmbBox );
902 m_cmbMime = new QComboBox( m_cmbBox );
903 lay->addWidget( m_cmbBox );
904}
905
906/*
907 * This will make sure that the return key in the name edit causes dialogs to close
908 */
909
910bool OFileSelector::eventFilter (QObject *o, QEvent *e)
911{
912 if ( e->type() == QEvent::KeyPress )
913 {
914 QKeyEvent *k = (QKeyEvent *)e;
915 if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
916 {
917 emit ok();
918 return true;
919 }
920 }
921 return false;
922}
923
924/*
925 * This will insert the MimeTypes into the Combo Box
926 * And also connect the changed signal
927 *
928 * AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
929 */
930void OFileSelector::initMime()
931{
932 MimeTypes::Iterator it;
933 for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it )
934 {
935 m_cmbMime->insertItem( it.key() );
936 }
937 m_cmbMime->setCurrentItem( 0 );
938
939 connect( m_cmbMime, SIGNAL(activated(int) ),
940 this, SLOT(slotMimeTypeChanged() ) );
941
942}
943
944void OFileSelector::initViews()
945{
946 m_cmbView->insertItem( QObject::tr("Documents") );
947 m_cmbView->insertItem( QObject::tr("Files") );
948 m_cmbView->insertItem( QObject::tr("All Files") );
949 connect(m_cmbView, SIGNAL(activated( const QString& ) ),
950 this, SLOT(slotViewChange( const QString& ) ) );
951
952
953 m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
954
955 /* see above why add both */
956 OFileViewInterface* in = new OFileViewFileSystem( this );
957 m_views.insert( QObject::tr("Files"), in );
958 m_views.insert( QObject::tr("All Files"), in );
959}
960
961OFileSelector::~OFileSelector()
962{
963}
964
965const DocLnk* OFileSelector::selected()
966{
967 DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
968 return lnk;
969}
970
971QString OFileSelector::selectedName()const
972{
973 return currentView()->selectedName();
974}
975
976QString OFileSelector::selectedPath()const
977{
978 return currentView()->selectedPath();
979}
980
981QString OFileSelector::directory()const
982{
983 return currentView()->directory();
984}
985
986DocLnk OFileSelector::selectedDocument()const
987{
988 return currentView()->selectedDocument();
989}
990
991int OFileSelector::fileCount()const
992{
993 return currentView()->fileCount();
994}
995
996void OFileSelector::reread()
997{
998 return currentView()->reread();
999}
1000
1001OFileViewInterface* OFileSelector::currentView()const
1002{
1003 return m_current;
1004}
1005
1006bool OFileSelector::showNew()const
1007{
1008 return m_shNew;
1009}
1010
1011bool OFileSelector::showClose()const
1012{
1013 return m_shClose;
1014}
1015
1016MimeTypes OFileSelector::mimeTypes()const
1017{
1018 return m_mimeType;
1019}
1020
1021int OFileSelector::mode()const
1022{
1023 return m_mode;
1024}
1025
1026int OFileSelector::selector()const
1027{
1028 return m_selector;
1029}
1030
1031QStringList OFileSelector::currentMimeType()const
1032{
1033 return m_mimeType[m_cmbMime->currentText()];
1034}
1035
1036void OFileSelector::slotMimeTypeChanged()
1037{
1038 reread();
1039}
1040
1041void OFileSelector::slotDocLnkBridge( const DocLnk& lnk)
1042{
1043 m_lneEdit->setText( lnk.name() );
1044 emit fileSelected( lnk );
1045 emit fileSelected( lnk.name() );
1046}
1047
1048void OFileSelector::slotFileBridge( const QString& str)
1049{
1050 DocLnk lnk( str );
1051 emit fileSelected( lnk );
1052}
1053
1054void OFileSelector::slotViewChange( const QString& view )
1055{
1056 OFileViewInterface* interface = m_views[view];
1057 if (!interface)
1058 return;
1059
1060 interface->activate( view );
1061 if (m_current)
1062 m_stack->removeWidget( m_current->widget( m_stack ) );
1063
1064 static int id = 1;
1065
1066 m_stack->addWidget( interface->widget(m_stack), id );
1067 m_stack->raiseWidget( id );
1068
1069 interface->reread();
1070 m_current = interface;
1071
1072 id++;
1073}
1074
1075void OFileSelector::setNewVisible( bool b )
1076{
1077 m_shNew = b;
1078 currentView()->reread();
1079}
1080
1081void OFileSelector::setCloseVisible( bool b )
1082{
1083 m_shClose = b;
1084 currentView()->reread();
1085}
1086
1087void OFileSelector::setNameVisible( bool b )
1088{
1089 if ( b )
1090 m_nameBox->show();
1091 else
1092 m_nameBox->hide();
1093}
1094
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h
new file mode 100644
index 0000000..7abe8b7
--- a/dev/null
+++ b/libopie2/opieui/fileselector/ofileselector.h
@@ -0,0 +1,161 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29/*
30 This is based on code and ideas of
31 L. J. Potter ljp@llornkcor.com
32 Thanks a lot
33*/
34
35#ifndef OFILESELECTOR_H
36#define OFILESELECTOR_H
37
38/* OPIE */
39#include <qpe/applnk.h>
40
41/* QT */
42#include <qlist.h>
43#include <qwidget.h>
44#include <qmap.h>
45#include <qvaluelist.h>
46#include <qstringlist.h>
47
48class QLineEdit;
49class QComboBox;
50class QWidgetStack;
51class QHBox;
52
53typedef QMap<QString, QStringList> MimeTypes;
54
55namespace Opie
56{
57
58class OFileViewInterface;
59class OFileViewFileListView;
60
61class OFileSelector : public QWidget
62{
63 Q_OBJECT
64 friend class Opie::OFileViewInterface;
65 friend class Opie::OFileViewFileListView;
66
67public:
68 enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 };
69 // enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
70 enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
71 // enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};
72
73 OFileSelector(QWidget* parent, int mode, int selector,
74 const QString& dirName,
75 const QString& fileName,
76 const MimeTypes& mimetypes = MimeTypes(),
77 bool newVisible = FALSE, bool closeVisible = FALSE );
78
79 OFileSelector(const QString& mimeFilter, QWidget* parent,
80 const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE );
81 ~OFileSelector();
82
83 const DocLnk* selected();
84
85 QString selectedName()const;
86 QString selectedPath()const;
87 QString directory()const;
88
89 DocLnk selectedDocument()const;
90
91 int fileCount()const;
92 void reread();
93
94 int mode()const;
95 int selector()const;
96
97
98 void setNewVisible( bool b );
99 void setCloseVisible( bool b );
100 void setNameVisible( bool b );
101
102signals:
103 void dirSelected( const QString& );
104 void fileSelected( const DocLnk& );
105 void fileSelected( const QString& );
106 void newSelected( const DocLnk& );
107 void closeMe();
108 void ok();
109 void cancel();
110
111 /* used by the ViewInterface */
112private:
113 bool showNew()const;
114 bool showClose()const;
115 MimeTypes mimeTypes()const;
116 QStringList currentMimeType()const;
117
118private:
119 /* inits the Widgets */
120 void initUI();
121 /* inits the MimeType ComboBox content + connects signals and slots */
122 void initMime();
123 /* init the Views :) */
124 void initViews();
125
126private:
127 QLineEdit* m_lneEdit; // the LineEdit for the Name
128 QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
129 QWidgetStack* m_stack; // our widget stack which will contain the views
130 OFileViewInterface* currentView() const; // returns the currentView
131 OFileViewInterface* m_current; // here is the view saved
132 bool m_shNew : 1; // should we show New?
133 bool m_shClose : 1; // should we show Close?
134 MimeTypes m_mimeType; // list of mimetypes
135
136 QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
137 QHBox* m_nameBox; // the LineEdit + Label is hold here
138 QHBox* m_cmbBox; // this holds the two combo boxes
139
140 QString m_startDir;
141 int m_mode;
142 int m_selector;
143
144 struct Data; // used for future versions
145 Data *d;
146
147private slots:
148 void slotMimeTypeChanged();
149
150 /* will set the text of the lineedit and emit a fileChanged signal */
151 void slotDocLnkBridge( const DocLnk& );
152 void slotFileBridge( const QString& );
153 void slotViewChange( const QString& );
154
155 bool eventFilter (QObject *o, QEvent *e);
156
157};
158
159};
160
161#endif
diff --git a/libopie2/opieui/fileselector/ofileselector_p.h b/libopie2/opieui/fileselector/ofileselector_p.h
new file mode 100644
index 0000000..818ced9
--- a/dev/null
+++ b/libopie2/opieui/fileselector/ofileselector_p.h
@@ -0,0 +1,191 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef OFILESELECTOR_PRIVATE_H
30#define OFILESELECTOR_PRIVATE_H
31
32/* OPIE */
33#include <qpe/applnk.h>
34#include <qpe/fileselector.h>
35
36/* QT */
37#include <qmap.h>
38#include <qstringlist.h>
39#include <qwidget.h>
40#include <qlistview.h>
41
42/*
43 * How to avoid having really two different objects
44 * for Extended and ExtendedAll
45 * The only difference is the Lister...
46 * a) static object?
47 * b) leave some object inside the OFileSelector which can be used?
48 * c) when switching views tell which view we want o have.. internally we can switch then
49 *
50 * I'll take c) -zecke
51 */
52
53typedef QMap<QString, QStringList> MimeTypes;
54
55/* the View Interface */
56class QFileInfo;
57class QToolButton;
58
59namespace Opie
60{
61
62class OFileSelector;
63
64class OFileViewInterface
65{
66public:
67 OFileViewInterface( OFileSelector* selector );
68 virtual ~OFileViewInterface();
69 virtual QString selectedName()const = 0;
70 virtual QString selectedPath()const = 0;
71 virtual QString directory()const = 0;
72 virtual void reread() = 0;
73 virtual int fileCount()const = 0;
74 virtual DocLnk selectedDocument()const;
75 virtual QWidget* widget( QWidget* parent) = 0;
76 virtual void activate( const QString& );
77 QString name()const;
78protected:
79 OFileSelector* selector()const;
80 void setName( const QString& );
81 bool showNew()const;
82 bool showClose()const;
83 MimeTypes mimeTypes()const;
84 QStringList currentMimeType()const;
85 QString startDirectory()const;
86protected:
87 void ok();
88 void cancel();
89 void closeMe();
90 void fileSelected( const QString& );
91 void fileSelected( const DocLnk& );
92 void setCurrentFileName( const QString& );
93 QString currentFileName()const;
94
95private:
96 QString m_name;
97 OFileSelector* m_selector;
98};
99
100
101/* THE Document View hosting a FileSelector*/
102class ODocumentFileView : public OFileViewInterface
103{
104public:
105 ODocumentFileView( OFileSelector* selector );
106 ~ODocumentFileView();
107
108 QString selectedName() const;
109 QString selectedPath() const;
110
111 QString directory() const;
112 void reread();
113 int fileCount()const;
114 DocLnk selectedDocument()const;
115
116 QWidget* widget( QWidget* parent );
117
118private:
119 mutable FileSelector* m_selector;
120
121};
122
123
124class OFileSelectorItem : public QListViewItem
125{
126public:
127 OFileSelectorItem( QListView* view, const QPixmap& pixmap,
128 const QString& path, const QString& date,
129 const QString& size, const QString& mDir,
130 bool isLocked = false, bool isDir = false );
131 ~OFileSelectorItem();
132 bool isLocked()const;
133 bool isDir()const;
134 QString directory()const;
135 QString path()const;
136 QString key(int id, bool )const;
137
138private:
139 bool m_locked : 1;
140 bool m_isDir : 1;
141 QString m_dir;
142};
143
144class OFileViewFileListView : public QWidget
145{
146 Q_OBJECT
147public:
148 OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector );
149 ~OFileViewFileListView();
150
151 OFileSelectorItem* currentItem()const;
152 void reread( bool all = false );
153 int fileCount()const;
154 QString currentDir()const;
155protected:
156 bool eventFilter (QObject *o, QEvent *e);
157private slots:
158 void slotNew(); // will emit newSelected
159 void cdUP();
160 void cdHome();
161 void cdDoc();
162 void changeDir( const QString& );
163 void slotCurrentChanged( QListViewItem* );
164 void slotClicked(int, QListViewItem*, const QPoint&, int );
165 void slotFSActivated(int);
166
167protected:
168 OFileSelector* selector();
169
170private:
171 QMap<QString, QString> m_dev;
172 bool m_all : 1;
173 OFileSelector* m_sel;
174 QPopupMenu* m_fsPop;
175 bool compliesMime( const QString& );
176 QStringList m_mimes; // used in compy mime
177 QString m_currentDir;
178 QToolButton *m_btnNew, *m_btnClose;
179 void connectSlots();
180 void addFile( QFileInfo* info, bool symlink = FALSE );
181 void addDir ( QFileInfo* info, bool symlink = FALSE );
182 void addSymlink( QFileInfo* info, bool = FALSE );
183
184
185private:
186 QListView* m_view;
187};
188
189};
190
191#endif
diff --git a/libopie2/opieui/fileselector/ofileview.h b/libopie2/opieui/fileselector/ofileview.h
new file mode 100644
index 0000000..495401b
--- a/dev/null
+++ b/libopie2/opieui/fileselector/ofileview.h
@@ -0,0 +1,95 @@
1/*
2               =. This file is part of the OPIE Project
3             .=l. Copyright (C) 2002 Holger Freyther <zecke@handhelds.org>
4           .>+-=
5 _;:,     .>    :=|. This library is free software; you can
6.> <`_,   >  .   <= redistribute it and/or modify it under
7:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
8.="- .-=="i,     .._ License as published by the Free Software
9 - .   .-<_>     .<> Foundation; either version 2 of the License,
10     ._= =}       : or (at your option) any later version.
11    .%`+i>       _;_.
12    .i_,=:_.      -<s. This library is distributed in the hope that
13     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
14    : ..    .:,     . . . without even the implied warranty of
15    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
16  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
17..}^=.=       =       ; Library General Public License for more
18++=   -.     .`     .: details.
19 :     =  ...= . :.=-
20 -.   .:....=;==+<; You should have received a copy of the GNU
21  -_. . .   )=.  = Library General Public License along with
22    --        :-=` this library; see the file COPYING.LIB.
23 If not, write to the Free Software Foundation,
24 Inc., 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA.
26
27*/
28
29#ifndef OFILEVIEW_H
30#define OFILEVIEW_H
31
32/* QT */
33#include <qobject.h>
34#include <qwidget.h>
35
36class QFileInfo;
37class QDir;
38class DocLnk;
39
40namespace Opie
41{
42
43/**
44 * A OFileView is a specialised View for the
45 * OFileSelector
46 * With a View you can chage the user visible
47 * representation of a OFileLister
48 * OFileView is just a basic interface which helps you to
49 * write new views
50 */
51class OFileView : public QWidget
52{
53 Q_OBJECT
54public:
55 OFileView(QWidget *widget,
56 const char *name );
57
58 OFileView();
59
60 virtual void addFile(const QString &mine,
61 QFileInfo *info,
62 bool isSymlink = FALSE ) = 0;
63
64 virtual void addDir (const QString &mine,
65 QFileInfo *info,
66 bool isSymlink = FALSE ) = 0;
67
68 virtual void addSymlink(const QString &mime,
69 QFileInfo *info,
70 bool isSymlink = FALSE ) = 0;
71
72 virtual void cd(const QString &path ) = 0;
73signals:
74 void fileSelected(const QString &);
75 void fileSelected(const DocLnk & );
76 void contextMenu();
77 void changedDir(const QString &);
78 void changedDir(const QDir & );
79};
80
81
82class OFileViewFactory
83{
84 // Q_OBJECT
85public:
86 OFileViewFactory() {} ;
87 virtual ~OFileViewFactory() = 0;
88
89 OFileView* newView(QWidget *parent, const char *name );
90 QString name()const;
91};
92
93};
94
95#endif
diff --git a/libopie2/opieui/ocheckitem.cpp b/libopie2/opieui/ocheckitem.cpp
new file mode 100644
index 0000000..45f27ee
--- a/dev/null
+++ b/libopie2/opieui/ocheckitem.cpp
@@ -0,0 +1,127 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include <opie2/ocheckitem.h>
31
32/* QT */
33#include <qpainter.h>
34
35using namespace Opie;
36
37/**
38 * Constructs an CheckItem with a QTable as parent
39 * and a sort key for.
40 * The sort key will be used by QTable to sort the table later
41 * @param t The parent QTable where the check item belongs
42 * @param key A sort key
43 */
44OCheckItem::OCheckItem( QTable *t, const QString &key )
45 :QTableItem( t, Never, "" ), m_checked( FALSE ), m_sortKey( key )
46{}
47
48/**
49 * reimplemted for internal reasons
50 * @return Returns the sort key of the Item
51 * @see QTableItem
52 */
53QString OCheckItem::key() const
54{
55 return m_sortKey;
56}
57
58/**
59 * This method can check or uncheck the item. It will
60 * call QTable to update the cell.
61 *
62 * @param b Whether to check or uncheck the item
63 */
64void OCheckItem::setChecked( bool b )
65{
66 m_checked = b;
67 table()->updateCell( row(), col() );
68}
69
70/**
71 * This will toggle the item. If it is checked it'll get
72 * unchecked by this method or vice versa.
73 */
74void OCheckItem::toggle()
75{
76 m_checked = !m_checked;
77}
78
79/**
80 * This will return the state of the item.
81 *
82 * @return Returns true if the item is checked
83 */
84bool OCheckItem::isChecked() const
85{
86 return m_checked;
87}
88
89/**
90 * @internal
91 * This paints the item
92 */
93void OCheckItem::paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool )
94{
95 p->fillRect( 0, 0, cr.width(), cr.height(), cg.brush( QColorGroup::Base ) );
96
97 int marg = ( cr.width() - BoxSize ) / 2;
98 int x = 0;
99 int y = ( cr.height() - BoxSize ) / 2;
100 p->setPen( QPen( cg.text() ) );
101 p->drawRect( x + marg, y, BoxSize, BoxSize );
102 p->drawRect( x + marg+1, y+1, BoxSize-2, BoxSize-2 );
103 p->setPen( darkGreen );
104 x += 1;
105 y += 1;
106 if ( m_checked )
107 {
108 QPointArray a( 7*2 );
109 int i, xx, yy;
110 xx = x+1+marg;
111 yy = y+2;
112 for ( i=0; i<3; i++ )
113 {
114 a.setPoint( 2*i, xx, yy );
115 a.setPoint( 2*i+1, xx, yy+2 );
116 xx++; yy++;
117 }
118 yy -= 2;
119 for ( i=3; i<7; i++ )
120 {
121 a.setPoint( 2*i, xx, yy );
122 a.setPoint( 2*i+1, xx, yy+2 );
123 xx++; yy--;
124 }
125 p->drawLineSegments( a );
126 }
127}
diff --git a/libopie2/opieui/ocheckitem.h b/libopie2/opieui/ocheckitem.h
new file mode 100644
index 0000000..db2e832
--- a/dev/null
+++ b/libopie2/opieui/ocheckitem.h
@@ -0,0 +1,86 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OCHECKITEM_H_
31#define OCHECKITEM_H_
32
33/* QT */
34#include <qtable.h>
35
36namespace Opie
37{
38
39/**
40 * This class represents a checkable QTableItem. This can
41 * be added to any QTable.
42 *
43 *
44 * @see QTable
45 * @see QTableItem
46 * @short An checkable QTableItem
47 * @version 1.0
48 * @author Stefan Eilers ( eilers@handhelds.org )
49 **/
50
51class OCheckItem : public QTableItem
52{
53public:
54 /** The size of a box currently unused */
55 enum Size { BoxSize = 10 };
56 OCheckItem( QTable *t, const QString &sortkey );
57
58 virtual void setChecked( bool b );
59 virtual void toggle();
60 bool isChecked() const;
61 /**
62 * @short Set the sort key
63 * @reimp
64 */
65 void setKey( const QString &key ) { m_sortKey = key; }
66 virtual QString key() const;
67
68 /**
69 * @short Paint the Checkitem
70 * @reimp
71 */
72 void paint( QPainter *p, const QColorGroup &cg, const QRect &cr, bool selected );
73
74 //static const int BoxSize = 10;
75
76private:
77 class OCheckItemPrivate;
78 OCheckItemPrivate *d;
79 bool m_checked : 1;
80 QString m_sortKey;
81
82};
83
84};
85
86#endif
diff --git a/libopie2/opieui/oclickablelabel.cpp b/libopie2/opieui/oclickablelabel.cpp
new file mode 100644
index 0000000..4c4e581
--- a/dev/null
+++ b/libopie2/opieui/oclickablelabel.cpp
@@ -0,0 +1,173 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Maximillian Reiß <harlekin@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include <opie2/oclickablelabel.h>
31
32using namespace Opie;
33
34/**
35 * This constructs the clickable ButtonLabel
36 *
37 * @param parent The parent of this label
38 * @param name A name of this label @see QObject
39 * @param fl The windowing flags
40 */
41OClickableLabel::OClickableLabel(QWidget* parent, const char* name, WFlags fl)
42 :QLabel(parent,name,fl)
43{
44 textInverted=false;
45 isToggle=false;
46 isDown=false;
47 showState(false);
48 setFrameShadow(Sunken);
49}
50
51/**
52 * This method makes the label behave as a toggle button
53 *
54 * @param t Whether or not to behave like a toggle button
55 */
56void OClickableLabel::setToggleButton(bool t)
57{
58 isToggle=t;
59}
60
61/**
62 * @internal
63 */
64void OClickableLabel::mousePressEvent( QMouseEvent * /*e*/ )
65{
66 if (isToggle && isDown)
67 {
68 showState(false);
69 }
70 else
71 {
72 showState(true);
73 }
74}
75
76/**
77 * @internal
78 */
79void OClickableLabel::mouseReleaseEvent( QMouseEvent *e )
80{
81 if (rect().contains(e->pos()) && isToggle) isDown=!isDown;
82
83 if (isToggle && isDown)
84 {
85 showState(true);
86 }
87 else
88 {
89 showState(false);
90 }
91
92 if (rect().contains(e->pos()))
93 {
94 if (isToggle)
95 {
96 emit toggled(isDown);
97 }
98 emit clicked();
99 }
100}
101
102/**
103 * @internal
104 */
105void OClickableLabel::mouseMoveEvent( QMouseEvent *e )
106{
107 if (rect().contains(e->pos()))
108 {
109 if (isToggle && isDown)
110 {
111 showState(false);
112 }
113 else
114 {
115 showState(true);
116 }
117 }
118 else
119 {
120 if (isToggle && isDown)
121 {
122 showState(true);
123 }
124 else
125 {
126 showState(false);
127 }
128 }
129}
130
131/**
132 * this toggles the label and inverts the color of
133 * the label
134 * @param on
135 */
136void OClickableLabel::showState(bool on)
137{
138 if (on)
139 {
140 //setFrameShape(Panel);
141 setInverted(true);
142 setBackgroundMode(PaletteHighlight);
143 }
144 else
145 {
146 //setFrameShape(NoFrame);
147 setInverted(false);
148 setBackgroundMode(PaletteBackground);
149 }
150 repaint();
151}
152
153void OClickableLabel::setInverted(bool on)
154{
155 if ( (!textInverted && on) || (textInverted && !on) )
156 {
157 QPalette pal=palette();
158 QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground);
159 col.setRgb(255-col.red(),255-col.green(),255-col.blue());
160 pal.setColor(QPalette::Normal, QColorGroup::Foreground, col);
161 setPalette(pal);
162 textInverted=!textInverted;
163 }
164}
165
166/**
167 * @param on if the Label is down or up
168 */
169void OClickableLabel::setOn(bool on)
170{
171 isDown=on;
172 showState(isDown);
173}
diff --git a/libopie2/opieui/oclickablelabel.h b/libopie2/opieui/oclickablelabel.h
new file mode 100644
index 0000000..b224d61
--- a/dev/null
+++ b/libopie2/opieui/oclickablelabel.h
@@ -0,0 +1,103 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Maximillian Reiß <harlekin@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OCLICKABLELABEL_H
31#define OCLICKABLELABEL_H
32
33/* QT */
34#include <qlabel.h>
35
36namespace Opie
37{
38
39/**
40 * This class is a special QLabel which can behave
41 * as a QPushButton or QToggleButton.
42 * The reason to use a clickable is if you want to save space
43 * or you want to skip the border of a normal button
44 *
45 * <pre>
46 * QLabel* lbl = new OClickableLabel( parent, "PushLabel" );
47 * lbl->setPixmap( "config" );
48 * QWhatsThis::add( lbl, tr("Click here to do something") );
49 * </pre>
50 *
51 * @short A Label behaving as button
52 * @author Hakan Ardo, Maximillian Reiß ( harlekin@handhelds.org )
53 * @see QLabel
54 * @see QPushButton
55 * @see QToggleButton
56 * @version 1.0
57 */
58
59class OClickableLabel: public QLabel
60{
61 Q_OBJECT
62public:
63 OClickableLabel(QWidget* parent = 0, const char* name = 0,
64 WFlags fl = 0);
65 void setToggleButton(bool t);
66
67protected:
68 /** @internal */
69 void mousePressEvent( QMouseEvent *e );
70 /** @internal */
71 void mouseReleaseEvent( QMouseEvent *e );
72 /** @internal */
73 void mouseMoveEvent( QMouseEvent *e );
74
75public slots:
76 void setOn(bool on);
77signals:
78 /**
79 * emitted when the labels gets clicked
80 */
81 void clicked();
82
83 /**
84 * emitted when the labels gets toggled
85 * @param on the new new state of the label
86 */
87 void toggled(bool on);
88private:
89 bool isToggle : 1;
90 bool isDown : 1;
91 bool textInverted : 1;
92
93 void showState(bool on);
94 void setInverted(bool on);
95
96private:
97 class Private;
98 Private *d; // private d pointer
99};
100
101};
102
103#endif
diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro
index 61f9bbb..41db153 100644
--- a/libopie2/opieui/opieui.pro
+++ b/libopie2/opieui/opieui.pro
@@ -1,47 +1,57 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt warn_on debug 2CONFIG += qt warn_on debug
3DESTDIR = $(OPIEDIR)/lib 3DESTDIR = $(OPIEDIR)/lib
4HEADERS = olistview.h \ 4HEADERS = ocheckitem.h \
5 oclickablelabel.h \
6 odialog.h \
7 ofileselector.h \
8 ofileselector_p.h \
9 ofiledialog.h \
10 ofileview.h \
5 oimageeffect.h \ 11 oimageeffect.h \
12 olistview.h \
6 opixmapeffect.h \ 13 opixmapeffect.h \
7 opopupmenu.h \ 14 opopupmenu.h \
8 opixmapprovider.h \ 15 opixmapprovider.h \
9 oselector.h \ 16 oselector.h \
10 oversatileview.h \ 17 oversatileview.h \
11 oversatileviewitem.h \ 18 oversatileviewitem.h \
12 odialog.h \
13 omessagebox.h \ 19 omessagebox.h \
14 oresource.h \ 20 oresource.h \
15 otaskbarapplet.h \ 21 otaskbarapplet.h \
16 oseparator.h 22 oseparator.h
17 23
18SOURCES = olistview.cpp \ 24SOURCES = ocheckitem.cpp \
25 oclickablelabel.cpp \
26 ofileselector.cpp \
27 ofiledialog.cpp \
19 oimageeffect.cpp \ 28 oimageeffect.cpp \
29 olistview.cpp \
20 opixmapeffect.cpp \ 30 opixmapeffect.cpp \
21 opopupmenu.cpp \ 31 opopupmenu.cpp \
22 opixmapprovider.cpp \ 32 opixmapprovider.cpp \
23 oselector.cpp \ 33 oselector.cpp \
24 oversatileview.cpp \ 34 oversatileview.cpp \
25 oversatileviewitem.cpp \ 35 oversatileviewitem.cpp \
26 odialog.cpp \ 36 odialog.cpp \
27 oresource.cpp \ 37 oresource.cpp \
28 otaskbarapplet.cpp \ 38 otaskbarapplet.cpp \
29 oseparator.cpp 39 oseparator.cpp
30 40
31INTERFACES = 41INTERFACES =
32TARGET = opieui2 42TARGET = opieui2
33VERSION = 1.8.2 43VERSION = 1.8.3
34 44
35INCLUDEPATH += $(OPIEDIR)/include 45INCLUDEPATH += $(OPIEDIR)/include
36DEPENDPATH += $(OPIEDIR)/include 46DEPENDPATH += $(OPIEDIR)/include
37 47
38LIBS += -lopiecore2 48LIBS += -lopiecore2
39 49
40!contains( platform, x11 ) { 50!contains( platform, x11 ) {
41 include ( $(OPIEDIR)/include.pro ) 51 include ( $(OPIEDIR)/include.pro )
42} 52}
43 53
44contains( platform, x11 ) { 54contains( platform, x11 ) {
45 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 55 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
46} 56}
47 57
diff --git a/libqtaux/libqtaux.pro b/libqtaux/libqtaux.pro
index 2f7aa91..56ccc65 100644
--- a/libqtaux/libqtaux.pro
+++ b/libqtaux/libqtaux.pro
@@ -1,23 +1,25 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qte warn_on debug 2CONFIG += qte warn_on debug
3 3
4HEADERS = qcolordialog.h \ 4HEADERS = qcolordialog.h \
5 qsplitter.h \ 5 qsplitter.h \
6 qinputdialog.h \ 6 qinputdialog.h \
7 \ 7 \
8 ocolorpopupmenu.h 8 ocolorpopupmenu.h \
9 ocolorbutton.h
9 10
10 11
11SOURCES = qcolordialog.cpp \ 12SOURCES = qcolordialog.cpp \
12 qsplitter.cpp \ 13 qsplitter.cpp \
13 qinputdialog.cpp \ 14 qinputdialog.cpp \
14 \ 15 \
15 ocolorpopupmenu.cpp 16 ocolorpopupmenu.cpp \
17 ocolorbutton.cpp
16 18
17TARGET = qtaux2 19TARGET = qtaux2
18INCLUDEPATH += $(OPIEDIR)/include 20INCLUDEPATH += $(OPIEDIR)/include
19DESTDIR = $(OPIEDIR)/lib 21DESTDIR = $(OPIEDIR)/lib
20INTERFACES = 22INTERFACES =
21 23
22 24
23include ( $(OPIEDIR)/include.pro ) 25include ( $(OPIEDIR)/include.pro )
diff --git a/libqtaux/ocolorbutton.cpp b/libqtaux/ocolorbutton.cpp
new file mode 100644
index 0000000..d2ad873
--- a/dev/null
+++ b/libqtaux/ocolorbutton.cpp
@@ -0,0 +1,150 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#include "ocolorpopupmenu.h"
31#include "ocolorbutton.h"
32
33/* OPIE */
34#include <qpe/resource.h>
35
36/* QT */
37#include <qcolor.h>
38#include <qpixmap.h>
39#include <qimage.h>
40
41using namespace Opie;
42
43struct OColorButtonPrivate
44{
45 QPopupMenu *m_menu;
46 QColor m_color;
47};
48
49/**
50 * This concstructs a Color Button with @param color as the start color
51 * It'll use a OColorPopupMenu internally
52 *
53 * @param parent The parent of the Color Button
54 * @param color The color from where to start on
55 * @param name @see QObject
56 */
57OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name )
58 : QPushButton ( parent, name )
59{
60 d = new OColorButtonPrivate;
61
62 d-> m_menu = new OColorPopupMenu ( color, 0, 0 );
63 setPopup ( d-> m_menu );
64 //setPopupDelay ( 0 );
65 connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & )));
66
67 updateColor ( color );
68
69 QSize s = sizeHint ( ) + QSize ( 12, 0 );
70 setMinimumSize ( s );
71 setMaximumSize ( s. width ( ) * 2, s. height ( ));
72}
73
74/**
75 * This destructs the object
76 */
77OColorButton::~OColorButton ( )
78{
79 delete d;
80}
81
82/**
83 * @return Returns the current color of the button
84 */
85QColor OColorButton::color ( ) const
86{
87 return d-> m_color;
88}
89
90/**
91 * This method sets the color of the button
92 * @param c The color to be set.
93 */
94void OColorButton::setColor ( const QColor &c )
95{
96 updateColor ( c );
97}
98
99/**
100 * @internal
101 */
102void OColorButton::updateColor ( const QColor &c )
103{
104 d-> m_color = c;
105
106 QImage img ( 16, 16, 32 );
107 img. fill ( 0 );
108
109 int r, g, b;
110 c. rgb ( &r, &g, &b );
111
112 int w = img. width ( );
113 int h = img. height ( );
114
115 int dx = w * 20 / 100; // 15%
116 int dy = h * 20 / 100;
117
118 for ( int y = 0; y < h; y++ )
119 {
120 for ( int x = 0; x < w; x++ )
121 {
122 double alpha = 1.0;
123
124 if ( x < dx )
125 alpha *= ( double ( x + 1 ) / dx );
126 else if ( x >= w - dx )
127 alpha *= ( double ( w - x ) / dx );
128 if ( y < dy )
129 alpha *= ( double ( y + 1 ) / dy );
130 else if ( y >= h - dy )
131 alpha *= ( double ( h - y ) / dy );
132
133 int a = int ( alpha * 255.0 );
134 if ( a < 0 )
135 a = 0;
136 if ( a > 255 )
137 a = 255;
138
139 img. setPixel ( x, y, qRgba ( r, g, b, a ));
140 }
141 }
142 img. setAlphaBuffer ( true );
143
144 QPixmap pix;
145 pix. convertFromImage ( img );
146 setPixmap ( pix );
147
148 emit colorSelected ( c );
149}
150
diff --git a/libqtaux/ocolorbutton.h b/libqtaux/ocolorbutton.h
new file mode 100644
index 0000000..ca68f1f
--- a/dev/null
+++ b/libqtaux/ocolorbutton.h
@@ -0,0 +1,80 @@
1/*
2 This file is part of the Opie Project
3 Copyright (C) Robert Griebl <sandman@handhelds.org>
4 =. Copyright (C) The Opie Team <opie-devel@handhelds.org>
5 .=l.
6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details.
21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA.
28*/
29
30#ifndef OCOLORBUTTON_H
31#define OCOLORBUTTON_H
32
33/* QT*/
34#include <qpushbutton.h>
35
36class OColorButtonPrivate;
37class QColor;
38
39namespace Opie
40{
41
42/**
43 *
44 * @short A Button which will show a OColorPopupMenu
45 * @author Robert Griebl ( sandman@handhelds.org )
46 * @version 1.0
47 * @see QPushButton
48 */
49class OColorButton : public QPushButton
50{
51 Q_OBJECT
52public:
53 OColorButton ( QWidget *parent = 0, const QColor & = black, const char *name = 0 );
54 virtual ~OColorButton ( );
55
56 QColor color ( ) const;
57
58signals:
59 /**
60 * emitted when a color gets selected
61 */
62 void colorSelected ( const QColor & );
63
64public slots:
65 virtual void setColor ( const QColor & );
66
67protected slots:
68 /**
69 * @internal
70 */
71 virtual void updateColor ( const QColor & );
72
73private:
74 OColorButtonPrivate *d;
75};
76
77};
78
79#endif
80
diff --git a/libqtaux/ocolorpopupmenu.cpp b/libqtaux/ocolorpopupmenu.cpp
index 6a2321e..6c5f99c 100644
--- a/libqtaux/ocolorpopupmenu.cpp
+++ b/libqtaux/ocolorpopupmenu.cpp
@@ -1,173 +1,176 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net> 4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net>
5              Dan Williams <williamsdr@acm.org> 5              Dan Williams <williamsdr@acm.org>
6 =. 6 =.
7 .=l. 7 .=l.
8           .>+-= 8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can 9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under 10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software 12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License, 13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version. 14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_. 15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that 16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of 18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more 21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details. 22++=   -.     .`     .: details.
23 :     =  ...= . :.=- 23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU 24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with 25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB. 26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30 30
31*/ 31*/
32 32
33#include "ocolorpopupmenu.h" 33#include "ocolorpopupmenu.h"
34#include "qcolordialog.h" 34#include "qcolordialog.h"
35 35
36/* QT */
36#include <qaction.h> 37#include <qaction.h>
37#include <qlayout.h> 38#include <qlayout.h>
38#include <qpainter.h> 39#include <qpainter.h>
39 40
41using namespace Opie;
42
40OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name ) 43OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
41 : QFrame( parent, name ) 44 : QFrame( parent, name )
42{ 45{
43 m_color = color; 46 m_color = color;
44 47
45 setFixedSize( 16, 16 ); 48 setFixedSize( 16, 16 );
46 setActive( FALSE ); 49 setActive( FALSE );
47} 50}
48 51
49OColorPanelButton::~OColorPanelButton() 52OColorPanelButton::~OColorPanelButton()
50{ 53{
51} 54}
52 55
53void OColorPanelButton::setActive( bool active ) 56void OColorPanelButton::setActive( bool active )
54{ 57{
55 m_active = active; 58 m_active = active;
56 59
57 if ( m_active ) { 60 if ( m_active ) {
58 setFrameStyle( Panel | Sunken ); 61 setFrameStyle( Panel | Sunken );
59 } else { 62 } else {
60 setFrameStyle( NoFrame ); 63 setFrameStyle( NoFrame );
61 } 64 }
62} 65}
63 66
64void OColorPanelButton::enterEvent( QEvent* ) 67void OColorPanelButton::enterEvent( QEvent* )
65{ 68{
66 if ( !m_active ) { 69 if ( !m_active ) {
67 setFrameStyle( Panel | Sunken ); 70 setFrameStyle( Panel | Sunken );
68 } 71 }
69} 72}
70 73
71void OColorPanelButton::leaveEvent( QEvent* ) 74void OColorPanelButton::leaveEvent( QEvent* )
72{ 75{
73 if ( !m_active ) { 76 if ( !m_active ) {
74 setFrameStyle( NoFrame ); 77 setFrameStyle( NoFrame );
75 } 78 }
76} 79}
77 80
78void OColorPanelButton::paintEvent( QPaintEvent* e ) 81void OColorPanelButton::paintEvent( QPaintEvent* e )
79{ 82{
80 QFrame::paintEvent( e ); 83 QFrame::paintEvent( e );
81 84
82 QPainter painter; 85 QPainter painter;
83 painter.begin( this ); 86 painter.begin( this );
84 painter.fillRect( 2, 2, 12, 12, m_color ); 87 painter.fillRect( 2, 2, 12, 12, m_color );
85 painter.setPen( Qt::black ); 88 painter.setPen( Qt::black );
86 painter.drawRect( 2, 2, 12, 12 ); 89 painter.drawRect( 2, 2, 12, 12 );
87 painter.end(); 90 painter.end();
88} 91}
89 92
90void OColorPanelButton::mouseReleaseEvent( QMouseEvent* ) 93void OColorPanelButton::mouseReleaseEvent( QMouseEvent* )
91{ 94{
92 emit selected( m_color ); 95 emit selected( m_color );
93} 96}
94 97
95OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name ) 98OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name )
96 : QPopupMenu( parent, name ) 99 : QPopupMenu( parent, name )
97{ 100{
98 m_color = color; 101 m_color = color;
99 102
100 colorPanel = new QWidget( this ); 103 colorPanel = new QWidget( this );
101 104
102 colorLayout = new QGridLayout(colorPanel, 5, 6); 105 colorLayout = new QGridLayout(colorPanel, 5, 6);
103 106
104 addColor(QColor(255, 255, 255), 0, 1); 107 addColor(QColor(255, 255, 255), 0, 1);
105 addColor(QColor(192, 192, 192), 0, 2); 108 addColor(QColor(192, 192, 192), 0, 2);
106 addColor(QColor(128, 128, 128), 0, 3); 109 addColor(QColor(128, 128, 128), 0, 3);
107 addColor(QColor(64, 64, 64), 0, 4); 110 addColor(QColor(64, 64, 64), 0, 4);
108 addColor(QColor(0, 0, 0), 0, 5); 111 addColor(QColor(0, 0, 0), 0, 5);
109 112
110 addColor(QColor(255, 0, 0), 1, 0); 113 addColor(QColor(255, 0, 0), 1, 0);
111 addColor(QColor(255, 128, 0), 1, 1); 114 addColor(QColor(255, 128, 0), 1, 1);
112 addColor(QColor(255, 255, 0), 1, 2); 115 addColor(QColor(255, 255, 0), 1, 2);
113 addColor(QColor(128, 255, 0), 1, 3); 116 addColor(QColor(128, 255, 0), 1, 3);
114 addColor(QColor(0, 255, 0), 1, 4); 117 addColor(QColor(0, 255, 0), 1, 4);
115 addColor(QColor(0, 255, 128), 1, 5); 118 addColor(QColor(0, 255, 128), 1, 5);
116 119
117 addColor(QColor(128, 0, 0), 2, 0); 120 addColor(QColor(128, 0, 0), 2, 0);
118 addColor(QColor(128, 64, 0), 2, 1); 121 addColor(QColor(128, 64, 0), 2, 1);
119 addColor(QColor(128, 128, 0), 2, 2); 122 addColor(QColor(128, 128, 0), 2, 2);
120 addColor(QColor(64, 128, 0), 2, 3); 123 addColor(QColor(64, 128, 0), 2, 3);
121 addColor(QColor(0, 128, 0), 2, 4); 124 addColor(QColor(0, 128, 0), 2, 4);
122 addColor(QColor(0, 128, 64), 2, 5); 125 addColor(QColor(0, 128, 64), 2, 5);
123 126
124 addColor(QColor(0, 255, 255), 3, 0); 127 addColor(QColor(0, 255, 255), 3, 0);
125 addColor(QColor(0, 128, 255), 3, 1); 128 addColor(QColor(0, 128, 255), 3, 1);
126 addColor(QColor(0, 0, 255), 3, 2); 129 addColor(QColor(0, 0, 255), 3, 2);
127 addColor(QColor(128, 0, 255), 3, 3); 130 addColor(QColor(128, 0, 255), 3, 3);
128 addColor(QColor(255, 0, 255), 3, 4); 131 addColor(QColor(255, 0, 255), 3, 4);
129 addColor(QColor(255, 0, 128), 3, 5); 132 addColor(QColor(255, 0, 128), 3, 5);
130 133
131 addColor(QColor(0, 128, 128), 4, 0); 134 addColor(QColor(0, 128, 128), 4, 0);
132 addColor(QColor(0, 64, 128), 4, 1); 135 addColor(QColor(0, 64, 128), 4, 1);
133 addColor(QColor(0, 0, 128), 4, 2); 136 addColor(QColor(0, 0, 128), 4, 2);
134 addColor(QColor(64, 0, 128), 4, 3); 137 addColor(QColor(64, 0, 128), 4, 3);
135 addColor(QColor(128, 0, 128), 4, 4); 138 addColor(QColor(128, 0, 128), 4, 4);
136 addColor(QColor(128, 0, 64), 4, 5); 139 addColor(QColor(128, 0, 64), 4, 5);
137 140
138 insertItem( colorPanel ); 141 insertItem( colorPanel );
139 insertSeparator(); 142 insertSeparator();
140 insertItem(tr("More"),this,SLOT( moreColorClicked())); 143 insertItem(tr("More"),this,SLOT( moreColorClicked()));
141 /* 144 /*
142 QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" ); 145 QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" );
143 connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) ); 146 connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) );
144 chooseColorAction->addTo( this ); 147 chooseColorAction->addTo( this );
145 */ 148 */
146 activateItemAt( 0 ); 149 activateItemAt( 0 );
147} 150}
148 151
149OColorPopupMenu::~OColorPopupMenu() 152OColorPopupMenu::~OColorPopupMenu()
150{ 153{
151} 154}
152 155
153void OColorPopupMenu::addColor( const QColor& color, int row, int col ) 156void OColorPopupMenu::addColor( const QColor& color, int row, int col )
154{ 157{
155 OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel ); 158 OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel );
156 connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) ); 159 connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) );
157 colorLayout->addWidget( panelButton, row, col ); 160 colorLayout->addWidget( panelButton, row, col );
158} 161}
159 162
160void OColorPopupMenu::buttonSelected( const QColor& color ) 163void OColorPopupMenu::buttonSelected( const QColor& color )
161{ 164{
162 m_color = color; 165 m_color = color;
163 emit colorSelected( color ); 166 emit colorSelected( color );
164 hide(); 167 hide();
165} 168}
166 169
167void OColorPopupMenu::moreColorClicked() 170void OColorPopupMenu::moreColorClicked()
168{ 171{
169 QColor color = QColorDialog::getColor( m_color ); 172 QColor color = QColorDialog::getColor( m_color );
170 m_color = color; 173 m_color = color;
171 emit colorSelected( color ); 174 emit colorSelected( color );
172 hide(); 175 hide();
173} 176}
diff --git a/libqtaux/ocolorpopupmenu.h b/libqtaux/ocolorpopupmenu.h
index 90cfbed..7ab3ca6 100644
--- a/libqtaux/ocolorpopupmenu.h
+++ b/libqtaux/ocolorpopupmenu.h
@@ -1,255 +1,262 @@
1/* 1/*
2                This file is part of the Opie Project 2                This file is part of the Opie Project
3 3
4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net> 4              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net>
5              Dan Williams <williamsdr@acm.org> 5              Dan Williams <williamsdr@acm.org>
6 =. 6 =.
7 .=l. 7 .=l.
8           .>+-= 8           .>+-=
9 _;:,     .>    :=|. This program is free software; you can 9 _;:,     .>    :=|. This program is free software; you can
10.> <`_,   >  .   <= redistribute it and/or modify it under 10.> <`_,   >  .   <= redistribute it and/or modify it under
11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 11:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
12.="- .-=="i,     .._ License as published by the Free Software 12.="- .-=="i,     .._ License as published by the Free Software
13 - .   .-<_>     .<> Foundation; either version 2 of the License, 13 - .   .-<_>     .<> Foundation; either version 2 of the License,
14     ._= =}       : or (at your option) any later version. 14     ._= =}       : or (at your option) any later version.
15    .%`+i>       _;_. 15    .%`+i>       _;_.
16    .i_,=:_.      -<s. This program is distributed in the hope that 16    .i_,=:_.      -<s. This program is distributed in the hope that
17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 17     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
18    : ..    .:,     . . . without even the implied warranty of 18    : ..    .:,     . . . without even the implied warranty of
19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 19    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 20  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
21..}^=.=       =       ; Library General Public License for more 21..}^=.=       =       ; Library General Public License for more
22++=   -.     .`     .: details. 22++=   -.     .`     .: details.
23 :     =  ...= . :.=- 23 :     =  ...= . :.=-
24 -.   .:....=;==+<; You should have received a copy of the GNU 24 -.   .:....=;==+<; You should have received a copy of the GNU
25  -_. . .   )=.  = Library General Public License along with 25  -_. . .   )=.  = Library General Public License along with
26    --        :-=` this library; see the file COPYING.LIB. 26    --        :-=` this library; see the file COPYING.LIB.
27 If not, write to the Free Software Foundation, 27 If not, write to the Free Software Foundation,
28 Inc., 59 Temple Place - Suite 330, 28 Inc., 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. 29 Boston, MA 02111-1307, USA.
30 30
31*/ 31*/
32 32
33#ifndef COLORPOPUPMENU_H 33#ifndef OCOLORPOPUPMENU_H
34#define COLORPOPUPMENU_H 34#define OCOLORPOPUPMENU_H
35
36/* QT */
35 37
36#include <qframe.h> 38#include <qframe.h>
37#include <qpopupmenu.h> 39#include <qpopupmenu.h>
38 40
39class QWidget; 41class QWidget;
40class QGridLayout; 42class QGridLayout;
41 43
44namespace Opie
45{
46
42/** 47/**
43 * @class OColorPanelButton 48 * @class OColorPanelButton
44 * @brief The OColorPanelButton class provides a button for color selection. 49 * @brief The OColorPanelButton class provides a button for color selection.
45 * 50 *
46 * @see OColorPopupMenu 51 * @see OColorPopupMenu
47 * 52 *
48 * The OColorPanelButton class provides a button for color selection. The button 53 * The OColorPanelButton class provides a button for color selection. The button
49 * is drawn with the desired color and no border. This class is used internally 54 * is drawn with the desired color and no border. This class is used internally
50 * by the OColorPopupMenu class to displaying colors in its menu. 55 * by the OColorPopupMenu class to displaying colors in its menu.
51 */ 56 */
52class OColorPanelButton : public QFrame 57class OColorPanelButton : public QFrame
53{ 58{
54 Q_OBJECT 59 Q_OBJECT
55 60
56public: 61public:
57 62
58/** 63/**
59 * @fn OColorPanelButton( const QColor& color, QWidget* parent = 0, const char* name = 0 ) 64 * @fn OColorPanelButton( const QColor& color, QWidget* parent = 0, const char* name = 0 )
60 * @brief Object constructor. 65 * @brief Object constructor.
61 * 66 *
62 * @param color Desired color. 67 * @param color Desired color.
63 * @param parent Pointer to parent of this control. 68 * @param parent Pointer to parent of this control.
64 * @param name Name of control. 69 * @param name Name of control.
65 * 70 *
66 * Constructs a new ColorPanelButton control with parent, name and desired color. 71 * Constructs a new ColorPanelButton control with parent, name and desired color.
67 */ 72 */
68 OColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0); 73 OColorPanelButton(const QColor& color, QWidget* parent = 0, const char* name = 0);
69 74
70/** 75/**
71 * @fn ~OColorPanelButton() 76 * @fn ~OColorPanelButton()
72 * @brief Object destructor. 77 * @brief Object destructor.
73 */ 78 */
74 ~OColorPanelButton(); 79 ~OColorPanelButton();
75 80
76/** 81/**
77 * @fn setActive( bool active ) 82 * @fn setActive( bool active )
78 * @brief Sets button selection state. 83 * @brief Sets button selection state.
79 * 84 *
80 * @param active Boolean indicator of new button state. 85 * @param active Boolean indicator of new button state.
81 * 86 *
82 * Changes button selection state. If button is selected, a highlighted border 87 * Changes button selection state. If button is selected, a highlighted border
83 * is drawn. 88 * is drawn.
84 */ 89 */
85 void setActive(bool active); 90 void setActive(bool active);
86 91
87/** 92/**
88 * @fn enterEvent( QEvent* e ) 93 * @fn enterEvent( QEvent* e )
89 * @brief Reimplemented for internal reasons. 94 * @brief Reimplemented for internal reasons.
90 * 95 *
91 * @param e Event currently being processed. 96 * @param e Event currently being processed.
92 * 97 *
93 * Reimplemented to ensure correct display of button based on whether it is 98 * Reimplemented to ensure correct display of button based on whether it is
94 * active or not. 99 * active or not.
95 */ 100 */
96 void enterEvent(QEvent* e); 101 void enterEvent(QEvent* e);
97 102
98/** 103/**
99 * @fn leaveEvent( QEvent* e ) 104 * @fn leaveEvent( QEvent* e )
100 * @brief Reimplemented for internal reasons. 105 * @brief Reimplemented for internal reasons.
101 * 106 *
102 * @param e Event currently being processed. 107 * @param e Event currently being processed.
103 * 108 *
104 * Reimplemented to ensure correct display of button based on whether it is 109 * Reimplemented to ensure correct display of button based on whether it is
105 * active or not. 110 * active or not.
106 */ 111 */
107 void leaveEvent(QEvent* e); 112 void leaveEvent(QEvent* e);
108 113
109/** 114/**
110 * @fn paintEvent( QPaintEvent* e ) 115 * @fn paintEvent( QPaintEvent* e )
111 * @brief Reimplemented for internal reasons. 116 * @brief Reimplemented for internal reasons.
112 * 117 *
113 * @param e Event currently being processed. 118 * @param e Event currently being processed.
114 * @reimp 119 * @reimp
115 * Reimplemented to ensure correct display of button. 120 * Reimplemented to ensure correct display of button.
116 */ 121 */
117 void paintEvent(QPaintEvent* e); 122 void paintEvent(QPaintEvent* e);
118 123
119/** 124/**
120 * @fn mouseReleaseEvent( QMouseEvent* e ) 125 * @fn mouseReleaseEvent( QMouseEvent* e )
121 * @brief Slot executed when button is pressed. 126 * @brief Slot executed when button is pressed.
122 * 127 *
123 * @param e Mouse event currently being processed. 128 * @param e Mouse event currently being processed.
124 * 129 *
125 * @see selected() 130 * @see selected()
126 * 131 *
127 * This slot executes when the button has been pressed. It emits the selected 132 * This slot executes when the button has been pressed. It emits the selected
128 * signal as notification that it has been pressed. 133 * signal as notification that it has been pressed.
129 */ 134 */
130 void mouseReleaseEvent(QMouseEvent* e); 135 void mouseReleaseEvent(QMouseEvent* e);
131 136
132signals: 137signals:
133 138
134/** 139/**
135 * @fn selected( const QColor& color ) 140 * @fn selected( const QColor& color )
136 * @brief Signal to indicate button has been pressed. 141 * @brief Signal to indicate button has been pressed.
137 * 142 *
138 * @param color Button color. 143 * @param color Button color.
139 * 144 *
140 * This signal is emitted when the button is pressed. It provides the color 145 * This signal is emitted when the button is pressed. It provides the color
141 * associated to this button. 146 * associated to this button.
142 */ 147 */
143 void selected(const QColor&); 148 void selected(const QColor&);
144 149
145private: 150private:
146 QColor m_color; 151 QColor m_color;
147 bool m_active : 1; 152 bool m_active : 1;
148 class ColorPanelButtonPrivate; 153 class ColorPanelButtonPrivate;
149 ColorPanelButtonPrivate *d; 154 ColorPanelButtonPrivate *d;
150}; 155};
151 156
152/** 157/**
153 * @class OColorPopupMenu 158 * @class OColorPopupMenu
154 * @brief The OColorPopupMenu class provides a small color selection 159 * @brief The OColorPopupMenu class provides a small color selection
155 * popup menu. 160 * popup menu.
156 * 161 *
157 * OColorPopupMenu is a derivation of TrollTech's QPopupMenu and provides 162 * OColorPopupMenu is a derivation of TrollTech's QPopupMenu and provides
158 * a small color selection popup menu which can be attached to another control 163 * a small color selection popup menu which can be attached to another control
159 * such as a toolbar button of menu item. 164 * such as a toolbar button of menu item.
160 * 165 *
161 * The popup menu displays 30 default colors available in a grid, and also 166 * The popup menu displays 30 default colors available in a grid, and also
162 * includes an option at the bottom to display a color selection dialog box for 167 * includes an option at the bottom to display a color selection dialog box for
163 * finer color control. 168 * finer color control.
164 */ 169 */
165class OColorPopupMenu : public QPopupMenu 170class OColorPopupMenu : public QPopupMenu
166{ 171{
167 Q_OBJECT 172 Q_OBJECT
168 173
169public: 174public:
170 175
171/** 176/**
172 * @fn OColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 ) 177 * @fn OColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 )
173 * @brief Object constructor. 178 * @brief Object constructor.
174 * 179 *
175 * @param color Initial color selected in menu. 180 * @param color Initial color selected in menu.
176 * @param parent Pointer to parent of this control. 181 * @param parent Pointer to parent of this control.
177 * @param name Name of control. 182 * @param name Name of control.
178 * 183 *
179 * Constructs a new OColorPopupMenu control with parent, name and initial color selected. 184 * Constructs a new OColorPopupMenu control with parent, name and initial color selected.
180 */ 185 */
181 // FIXME add Wflags? -zecke 186 // FIXME add Wflags? -zecke
182 OColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 ); 187 OColorPopupMenu( const QColor& color, QWidget* parent = 0, const char* name = 0 );
183 188
184/** 189/**
185 * @fn ~OColorPopupMenu() 190 * @fn ~OColorPopupMenu()
186 * @brief Object destructor. 191 * @brief Object destructor.
187 */ 192 */
188 ~OColorPopupMenu(); 193 ~OColorPopupMenu();
189 194
190private: 195private:
191 class ColorPopupMenuPrivate; 196 class ColorPopupMenuPrivate;
192 ColorPopupMenuPrivate *d; 197 ColorPopupMenuPrivate *d;
193 QColor m_color; 198 QColor m_color;
194 QWidget* colorPanel; 199 QWidget* colorPanel;
195 QGridLayout* colorLayout; 200 QGridLayout* colorLayout;
196 201
197/** 202/**
198 * @fn addColor( const QColor& color, int row, int col ) 203 * @fn addColor( const QColor& color, int row, int col )
199 * @brief Adds color selection option to popup menu. 204 * @brief Adds color selection option to popup menu.
200 * 205 *
201 * @param color Color to be displayed in menu. 206 * @param color Color to be displayed in menu.
202 * @param row Row where color is to appear in menu. 207 * @param row Row where color is to appear in menu.
203 * @param col Column where color is to appear in menu. 208 * @param col Column where color is to appear in menu.
204 * 209 *
205 * Adds a color selection option to popup menu. Used internally when 210 * Adds a color selection option to popup menu. Used internally when
206 * initially constructing the menu control. 211 * initially constructing the menu control.
207 */ 212 */
208 void addColor( const QColor& color, int row, int col ); 213 void addColor( const QColor& color, int row, int col );
209 214
210signals: 215signals:
211 216
212/** 217/**
213 * @fn colorSelected( const QColor& color ) 218 * @fn colorSelected( const QColor& color )
214 * @brief Signal to indicate color chosen from the menu. 219 * @brief Signal to indicate color chosen from the menu.
215 * 220 *
216 * @param color Color selected from the menu. 221 * @param color Color selected from the menu.
217 * 222 *
218 * This signal is emitted when a color has been selected either directly from 223 * This signal is emitted when a color has been selected either directly from
219 * the menu, or chosen from the color selection dialog. 224 * the menu, or chosen from the color selection dialog.
220 */ 225 */
221 void colorSelected( const QColor& color ); 226 void colorSelected( const QColor& color );
222 227
223protected slots: 228protected slots:
224 229
225/** 230/**
226 * @fn buttonSelected( const QColor& color ) 231 * @fn buttonSelected( const QColor& color )
227 * @brief Slot to process selected color. 232 * @brief Slot to process selected color.
228 * 233 *
229 * @param color Color selected from the menu. 234 * @param color Color selected from the menu.
230 * 235 *
231 * @see colorSelected() 236 * @see colorSelected()
232 * 237 *
233 * This slot executes when a color has been selected from the menu. It performs 238 * This slot executes when a color has been selected from the menu. It performs
234 * two functions: 239 * two functions:
235 * - Emit the colorSelected signal with the color selected. 240 * - Emit the colorSelected signal with the color selected.
236 * - Hide the menu. 241 * - Hide the menu.
237 */ 242 */
238 void buttonSelected( const QColor& color ); 243 void buttonSelected( const QColor& color );
239 244
240/** 245/**
241 * @fn moreColorClicked() 246 * @fn moreColorClicked()
242 * @brief Slot to process display color selection dialog. 247 * @brief Slot to process display color selection dialog.
243 * 248 *
244 * @see colorSelected() 249 * @see colorSelected()
245 * 250 *
246 * This slot executes when the 'More...' option is selected at the bottom of the menu. 251 * This slot executes when the 'More...' option is selected at the bottom of the menu.
247 * It performs the following functions: 252 * It performs the following functions:
248 * - Constructs and executes a QColorDialog to allow finer color selection. 253 * - Constructs and executes a QColorDialog to allow finer color selection.
249 * - Emit the colorSelected signal with the color selected. 254 * - Emit the colorSelected signal with the color selected.
250 * - Hide the menu. 255 * - Hide the menu.
251 */ 256 */
252 void moreColorClicked(); 257 void moreColorClicked();
253}; 258};
254 259
260};
261
255#endif // COLORPOPUPMENUANEL_H 262#endif // COLORPOPUPMENUANEL_H