summaryrefslogtreecommitdiff
path: root/libopie2/opieui
Side-by-side diff
Diffstat (limited to 'libopie2/opieui') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opieui/big-screen/obigscreen_p.h9
-rw-r--r--libopie2/opieui/big-screen/osplitter.cpp13
-rw-r--r--libopie2/opieui/big-screen/osplitter.h15
-rw-r--r--libopie2/opieui/big-screen/owidgetstack.cpp9
-rw-r--r--libopie2/opieui/big-screen/owidgetstack.h7
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.cpp2
-rw-r--r--libopie2/opieui/fileselector/ofiledialog.h7
-rw-r--r--libopie2/opieui/fileselector/ofileselector.cpp9
-rw-r--r--libopie2/opieui/fileselector/ofileselector.h19
-rw-r--r--libopie2/opieui/fileselector/ofileselector_p.h10
-rw-r--r--libopie2/opieui/fileselector/ofileview.h9
-rw-r--r--libopie2/opieui/oclickablelabel.cpp2
-rw-r--r--libopie2/opieui/oclickablelabel.h7
-rw-r--r--libopie2/opieui/odialog.cpp2
-rw-r--r--libopie2/opieui/odialog.h5
-rw-r--r--libopie2/opieui/ofontselector.cpp19
-rw-r--r--libopie2/opieui/ofontselector.h12
-rw-r--r--libopie2/opieui/oimageeffect.cpp7
-rw-r--r--libopie2/opieui/oimageeffect.h5
-rw-r--r--libopie2/opieui/olistview.cpp7
-rw-r--r--libopie2/opieui/olistview.h25
-rw-r--r--libopie2/opieui/opieui.pro3
-rw-r--r--libopie2/opieui/opixmapeffect.cpp2
-rw-r--r--libopie2/opieui/opixmapeffect.h6
-rw-r--r--libopie2/opieui/opixmapprovider.cpp2
-rw-r--r--libopie2/opieui/opixmapprovider.h8
-rw-r--r--libopie2/opieui/opopupmenu.cpp3
-rw-r--r--libopie2/opieui/opopupmenu.h5
-rw-r--r--libopie2/opieui/oselector.cpp18
-rw-r--r--libopie2/opieui/oselector.h5
-rw-r--r--libopie2/opieui/oseparator.cpp2
-rw-r--r--libopie2/opieui/oseparator.h5
-rw-r--r--libopie2/opieui/otabbar.cpp2
-rw-r--r--libopie2/opieui/otabbar.h7
-rw-r--r--libopie2/opieui/otabinfo.h7
-rw-r--r--libopie2/opieui/otabwidget.cpp2
-rw-r--r--libopie2/opieui/otabwidget.h8
-rw-r--r--libopie2/opieui/otaskbarapplet.cpp52
-rw-r--r--libopie2/opieui/otaskbarapplet.h49
-rw-r--r--libopie2/opieui/otimepicker.cpp15
-rw-r--r--libopie2/opieui/otimepicker.h19
-rw-r--r--libopie2/opieui/otimepickerbase.ui38
-rw-r--r--libopie2/opieui/oversatileview.cpp43
-rw-r--r--libopie2/opieui/oversatileview.h83
-rw-r--r--libopie2/opieui/oversatileviewitem.cpp2
-rw-r--r--libopie2/opieui/oversatileviewitem.h5
-rw-r--r--libopie2/opieui/owait.cpp2
-rw-r--r--libopie2/opieui/owait.h6
48 files changed, 378 insertions, 221 deletions
diff --git a/libopie2/opieui/big-screen/obigscreen_p.h b/libopie2/opieui/big-screen/obigscreen_p.h
index db8fc83..a85a56c 100644
--- a/libopie2/opieui/big-screen/obigscreen_p.h
+++ b/libopie2/opieui/big-screen/obigscreen_p.h
@@ -1,28 +1,31 @@
#ifndef OPIE_BIG_SCREEN_PRIVATE
#define OPIE_BIG_SCREEN_PRIVATE
/* QT */
#include <qstring.h>
class QWidget;
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
+namespace Private{
struct OSplitterContainer
{
bool operator==( const OSplitterContainer& o) const
{
if (widget != o.widget ) return false;
if (icon != o.icon ) return false;
if (name != o.name ) return false;
return true;
}
QWidget* widget;
QString icon;
QString name;
};
-};
+}
+}
+}
#endif
diff --git a/libopie2/opieui/big-screen/osplitter.cpp b/libopie2/opieui/big-screen/osplitter.cpp
index 89f3793..bcfd3a6 100644
--- a/libopie2/opieui/big-screen/osplitter.cpp
+++ b/libopie2/opieui/big-screen/osplitter.cpp
@@ -1,638 +1,639 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "osplitter.h"
/* OPIE */
#include <opie2/otabwidget.h>
/* QT */
#include <qvaluelist.h>
#include <qvbox.h>
-using namespace Opie;
+using namespace Opie::Ui;
+using namespace Opie::Ui::Private;
/**
*
* This is the constructor of OSplitter
* You might want to call setSizeChange to tell
* OSplitter to change its layout when a specefic
* mark was crossed. OSplitter sets a default value.
*
* You cann add widget with addWidget to the OSplitter.
* OSplitter supports also grouping of Splitters where they
* can share one OTabBar in small screen mode. This can be used
* for email clients like vies but see the example.
*
* @param orient The orientation wether to layout horizontal or vertical
* @param parent The parent of this widget
* @param name The name passed on to QObject
* @param fl Additional widgets flags passed to QWidget
*
* @short single c'tor of the OSplitter
*/
OSplitter::OSplitter( Orientation orient, QWidget* parent, const char* name, WFlags fl )
: QFrame( parent, name, fl )
{
m_orient = orient;
m_hbox = 0;
m_size_policy = 330;
setFontPropagation( AllChildren );
setPalettePropagation( AllChildren );
/* start by default with the tab widget */
m_tabWidget = 0;
m_parentTab = 0;
changeTab();
}
/**
* Destructor destructs this object and cleans up. All child
* widgets will be deleted
* @see addWidget
*/
OSplitter::~OSplitter()
{
qWarning("Deleted Splitter");
m_splitter.setAutoDelete( true );
m_splitter.clear();
delete m_hbox;
delete m_tabWidget;
}
/**
* Sets the label for the Splitter. This label will be used
* if a parent splitter is arranged as TabWidget but
* this splitter is in fullscreen mode. Then a tab with OSplitter::label()
* and iconName() gets added.
*
* @param name The name of the Label
*/
void OSplitter::setLabel( const QString& name )
{
m_name = name;
}
/**
* @see setLabel but this is for the icon retrieved by Resource
*
* @param name The name of the icon in example ( "zoom" )
*/
void OSplitter::setIconName( const QString& name )
{
m_icon = name;
}
/**
* returns the iconName
* @see setIconName
*/
QString OSplitter::iconName()const
{
return m_icon;
}
/**
* returns the label set with setLabel
* @see setLabel
*/
QString OSplitter::label()const
{
return m_name;
}
/**
* This function sets the size change policy of the splitter.
* If this size marked is crossed the splitter will relayout.
* Note: that depending on the set Orientation it'll either look
* at the width or height.
* Note: If you want to from side to side view to tabbed view you need
* to make sure that the size you supply is not smaller than the minimum
* size of your added widgets. Note that if you use widgets like QComboBoxes
* you need to teach them to accept smaller sizes as well @see QWidget::setSizePolicy
*
* @param width_height The mark that will be watched. Interpreted depending on the Orientation of the Splitter.
* @return void
*/
void OSplitter::setSizeChange( int width_height )
{
m_size_policy = width_height;
QSize sz(width(), height() );
QResizeEvent ev(sz, sz );
resizeEvent(&ev);
}
/**
* This functions allows to add another OSplitter and to share
* the OTabBar in small screen mode. The ownerships gets transfered.
* OSplitters are always added after normal widget items
*/
void OSplitter::addWidget( OSplitter* split )
{
m_splitter.append( split );
/*
* set tab widget
*/
if (m_tabWidget )
setTabWidget( m_parentTab );
else
{
- Opie::OSplitterContainer con;
+ OSplitterContainer con;
con.widget =split;
addToBox( con );
}
}
/*
* If in a tab it should be removed
* and if in a hbox the reparent kills it too
*/
/**
* This removes the splitter again. You currently need to call this
* before you delete or otherwise you can get mem corruption
* or other weird behaviour.
* Owner ship gets transfered back to you it's current parent
* is 0
*/
void OSplitter::removeWidget( OSplitter* split)
{
split->setTabWidget( 0 );
split->reparent( 0, 0, QPoint(0, 0) );
}
/**
* Adds a widget to the Splitter. The widgets gets inserted
* at the end of either the Box or TabWidget.
* Ownership gets transfered and the widgets gets reparented.
* Note: icon and label is only available on small screensizes
* if size is smaller than the mark
* Warning: No null checking of the widget is done. Only on debug
* a message will be outputtet
*
* @param wid The widget which will be added
* @param icon The icon of the possible Tab
* @param label The label of the possible Tab
*/
void OSplitter::addWidget( QWidget* wid, const QString& icon, const QString& label )
{
#ifdef DEBUG
if (!wid )
{
qWarning("Widget is not valid!");
return;
}
#endif
- Opie::OSplitterContainer cont;
+ OSplitterContainer cont;
cont.widget = wid;
cont.icon =icon;
cont.name = label;
m_container.append( cont );
/*
*
*/
if (!m_splitter.isEmpty() && (m_tabWidget || m_parentTab ) )
setTabWidget( m_parentTab );
else
{
if (m_hbox )
addToBox( cont );
else
addToTab( cont );
}
}
/**
* Removes the widget from the tab widgets if necessary.
* OSplitter drops ownership of this widget and the widget
* will be reparented i tto 0.
* The widget will not be deleted.
*
* @param w The widget to be removed
*/
void OSplitter::removeWidget( QWidget* w)
{
ContainerList::Iterator it;
for ( it = m_container.begin(); it != m_container.end(); ++it )
if ( (*it).widget == w )
break;
if (it == m_container.end() )
return;
/* only tab needs to be removed.. box recognizes it */
if ( !m_hbox )
removeFromTab( w );
/* Find reparent it and remove it from our list */
w->reparent( 0, 0, QPoint(0, 0));
it = m_container.remove( it );
}
/**
* This method will give focus to the widget. If in a tabwidget
* the tabbar will be changed
*
* @param w The widget which will be set the current one
*/
void OSplitter::setCurrentWidget( QWidget* w)
{
if (m_tabWidget )
m_tabWidget->setCurrentTab( w );
// else
// m_hbox->setFocus( w );
}
/**
* This is an overloaded member function and only differs in the
* argument it takes.
* Searches list of widgets for label. It'll pick the first label it finds
*
* @param label Label to look for. First match will be taken
*/
void OSplitter::setCurrentWidget( const QString& label )
{
ContainerList::Iterator it;
for (it = m_container.begin(); it != m_container.end(); ++it )
{
if ( (*it).name == label )
{
setCurrentWidget( (*it).widget );
break;
}
}
}
/**
* This will only work when the TabWidget is active
* If everything is visible this signal is kindly ignored
* @see OTabWidget::setCurrentTab(int)
*
* @param tab The tab to make current
*/
void OSplitter::setCurrentWidget( int tab )
{
if (m_tabWidget )
m_tabWidget->setCurrentTab( tab );
}
/**
* return the currently activated widget if in tab widget mode
* or null because all widgets are visible
*/
QWidget* OSplitter::currentWidget() const
{
if (m_tabWidget)
return m_tabWidget->currentWidget();
else if (m_parentTab )
return m_parentTab->currentWidget();
return 0l;
}
/* wrong */
#if 0
/**
* @reimplented for internal reasons
* returns the sizeHint of one of its sub widgets
*/
QSize OSplitter::sizeHint()const
{
if (m_parentTab )
return QFrame::sizeHint();
if (m_hbox )
return m_hbox->sizeHint();
else
return m_tabWidget->sizeHint();
}
QSize OSplitter::minimumSizeHint()const
{
if (m_parentTab )
return QFrame::minimumSizeHint();
if (m_hbox)
return m_hbox->sizeHint();
else
return m_tabWidget->sizeHint();
}
#endif
/**
* @reimplemented for internal reasons
*/
void OSplitter::resizeEvent( QResizeEvent* res )
{
QFrame::resizeEvent( res );
/*
*
*/
// qWarning("Old size was width = %d height = %d", res->oldSize().width(), res->oldSize().height() );
bool mode = true;
qWarning("New size is width = %d height = %d %s", res->size().width(), res->size().height(), name() );
if ( res->size().width() > m_size_policy &&
m_orient == Horizontal )
{
changeHBox();
mode = false;
}
else if ( (res->size().width() <= m_size_policy &&
m_orient == Horizontal ) ||
(res->size().height() <= m_size_policy &&
m_orient == Vertical ) )
{
changeTab();
}
else if ( res->size().height() > m_size_policy &&
m_orient == Vertical )
{
qWarning("Changng to vbox %s", name() );
changeVBox();
mode = false;
}
emit sizeChanged(mode, m_orient );
}
/*
* Adds a container to a tab either the parent tab
* or our own
*/
-void OSplitter::addToTab( const Opie::OSplitterContainer& con )
+void OSplitter::addToTab( const Opie::Ui::Private::OSplitterContainer& con )
{
QWidget *wid = con.widget;
// not needed widgetstack will reparent as well wid.reparent(m_tabWidget, wid->getWFlags(), QPoint(0, 0) );
if (m_parentTab )
m_parentTab->addTab( wid, con.icon, con.name );
else
m_tabWidget->addTab( wid, con.icon, con.name );
}
/*
* adds a container to the box
*/
-void OSplitter::addToBox( const Opie::OSplitterContainer& con )
+void OSplitter::addToBox( const Opie::Ui::Private::OSplitterContainer& con )
{
QWidget* wid = con.widget;
wid->reparent(m_hbox, 0, QPoint(0, 0) );
}
/*
* Removes a widget from the tab
*/
void OSplitter::removeFromTab( QWidget* wid )
{
if (m_parentTab )
m_parentTab->removePage( wid );
else
m_tabWidget->removePage( wid );
}
/*
* switches over to a OTabWidget layout
* it is recursive
*/
void OSplitter::changeTab()
{
/* if we're the owner of the tab widget */
if (m_tabWidget )
{
raise();
show();
m_tabWidget->setGeometry( frameRect() );
return;
}
qWarning(" New Tab Widget %s", name() );
/*
* and add all widgets this will reparent them
* delete m_hbox set it to 0
*
*/
OTabWidget *tab;
if ( m_parentTab )
{
hide();
tab = m_parentTab;
/* expensive but needed cause we're called from setTabWidget and resizeEvent*/
if (!m_container.isEmpty() )
{
ContainerList::Iterator it = m_container.begin();
for (; it != m_container.end(); ++it )
m_parentTab->removePage( (*it).widget );
}
}
else
tab = m_tabWidget = new OTabWidget( this );
connect(tab, SIGNAL(currentChanged(QWidget*) ),
this, SIGNAL(currentChanged(QWidget*) ) );
for ( ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it )
{
qWarning("Widget is %s", (*it).name.latin1() );
addToTab( (*it) );
}
for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() )
{
split->reparent(this, 0, QPoint(0, 0) );
split->setTabWidget( tab );
}
delete m_hbox;
m_hbox = 0;
if (!m_tabWidget )
return;
m_tabWidget->setGeometry( frameRect() );
m_tabWidget->show();
}
/*
* changes over to a box
* this is recursive as well
*/
void OSplitter::changeHBox()
{
if (m_hbox )
{
m_hbox->setGeometry( frameRect() );
return;
}
qWarning("new HBox %s", name() );
m_hbox = new QHBox( this );
commonChangeBox();
}
void OSplitter::changeVBox()
{
if (m_hbox )
{
m_hbox->setGeometry( frameRect() );
return;
}
qWarning("New VBOX %s", name() );
m_hbox = new QVBox( this );
commonChangeBox();
}
/*
* common box code
* first remove and add children
* the other splitters
* it is recursive as well due the call to setTabWidget
*/
void OSplitter::commonChangeBox()
{
qWarning(" Name of Splitters is %s", name() );
for (ContainerList::Iterator it = m_container.begin(); it != m_container.end(); ++it )
{
/* only if parent tab.. m_tabWidgets gets deleted and would do that as well */
if (m_parentTab )
removeFromTab( (*it).widget );
qWarning("Adding to box %s", (*it).name.latin1() );
addToBox( (*it) );
}
for ( OSplitter* split = m_splitter.first(); split; split = m_splitter.next() )
{
/* tell them the world had changed */
split->setTabWidget( 0 );
- Opie::OSplitterContainer con;
+ OSplitterContainer con;
con.widget = split;
// con.widget = split->m_tabWidget ? static_cast<QWidget*>(split->m_tabWidget)
// : static_cast<QWidget*>(split->m_hbox);
addToBox( con );
}
if (m_parentTab )
m_parentTab->addTab(m_hbox, iconName(), label() );
else
{
qWarning(" setting Box geometry for %s", name() );
m_hbox->setGeometry( frameRect() );
m_hbox->show();
delete m_tabWidget;
m_tabWidget = 0;
show(); // also show this widget
}
}
/*
* sets the tabwidget, removes tabs, and relayouts the widget
*/
void OSplitter::setTabWidget( OTabWidget* wid)
{
/* clean up cause m_parentTab will not be available for us */
if ( m_parentTab )
{
if (m_hbox )
m_parentTab->removePage( m_hbox );
else if (!m_container.isEmpty() )
{
ContainerList::Iterator it = m_container.begin();
for ( ; it != m_container.end(); ++it )
m_parentTab->removePage( (*it).widget );
}
}
/* the parent Splitter changed so either make us indepent or dep */
m_parentTab = wid;
QWidget *tab = m_tabWidget;
QWidget *box = m_hbox;
m_hbox = 0; m_tabWidget = 0;
if ( layoutMode() )
changeTab();
else if (m_orient == Horizontal )
changeHBox();
else
changeVBox();
/* our own crap is added and children from change* */
delete tab;
delete box;
}
#if 0
void OSplitter::reparentAll()
{
if (m_container.isEmpty() )
return;
ContainerList::Iterator it = m_container.begin();
for ( ; it != m_container.end(); ++it )
(*it).wid->reparent(0, 0, QPoint(0, 0) );
}
#endif
/**
* @internal
*/
bool OSplitter::layoutMode()const
{
if ( size().width() > m_size_policy &&
m_orient == Horizontal )
{
return false;
}
else if ( size().height() > m_size_policy &&
m_orient == Vertical )
{
return false;
}
return true;
}
diff --git a/libopie2/opieui/big-screen/osplitter.h b/libopie2/opieui/big-screen/osplitter.h
index 2daae7f..7b5ea53 100644
--- a/libopie2/opieui/big-screen/osplitter.h
+++ b/libopie2/opieui/big-screen/osplitter.h
@@ -1,150 +1,151 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
-
+
*/
#ifndef OSPLITTER_H
#define OSPLITTER_H
#include "obigscreen_p.h"
/* QT */
#include <qframe.h>
#include <qlist.h>
#include <qstring.h>
#include <qvaluelist.h>
class QHBox;
//template class QValueList<Opie::OSplitterContainer>;
/*
* TODO
* -check API docu
* -one more example
* -allow inserting at a position
*/
-namespace Opie
-{
+namespace Opie{
+namespace Ui {
class OTabWidget;
/**
*
* If you've widgets that could be placed side by side but you think
* on small resolutions is not enough place but it would really make sense
* on bigger resolutions this class will help you.
* You can add as many widgets you want to it. Set a poliy on which width/height it
* should switch the layout.
* You can either say to place widgets vertical or horizontal.
* This class uses QHBox, QVBox and QTAbWidget internally.
* OSplitter takes ownership of the widgets
*
* @since 1.2
*
* @short a small dynamically changing its layout to store two or more widgets side by side
* @version 0.1
* @author zecke
*/
class OSplitter : public QFrame
{
Q_OBJECT
public:
- typedef QValueList<Opie::OSplitterContainer> ContainerList;
+ typedef QValueList<Opie::Ui::Private::OSplitterContainer> ContainerList;
OSplitter( Qt::Orientation = Horizontal, QWidget *parent = 0,
const char* name = 0, WFlags fl = 0 );
~OSplitter();
void setLabel( const QString& name );
void setIconName( const QString& name );
QString label()const;
QString iconName()const;
void setSizeChange( int width_height );
void addWidget( OSplitter* splitter );
void addWidget( QWidget* wid, const QString& icon, const QString& label );
void removeWidget( QWidget* );
void removeWidget( OSplitter* );
void setCurrentWidget( QWidget* );
void setCurrentWidget( const QString& label );
void setCurrentWidget( int );
QWidget* currentWidget()const;
signals:
/**
* Emitted if in tab and comes directly from the tab widget
*
*/
void currentChanged( QWidget* );
/**
* emitted whenever a border is crossed
* true if in small screen mode
* false if in bigscreen
* this signal is emitted after the layout switch
* @param b The layout mode
* @param ori The orientation
*/
void sizeChanged( bool b, Orientation ori);
public:
// QSize sizeHint()const;
// QSize minimumSizeHint()const;
protected:
void resizeEvent( QResizeEvent* );
private:
/* true if OTabMode */
bool layoutMode()const;
// void reparentAll();
void setTabWidget( OTabWidget*);
- void addToTab( const Opie::OSplitterContainer& );
- void addToBox( const Opie::OSplitterContainer& );
+ void addToTab( const Opie::Ui::Private::OSplitterContainer& );
+ void addToBox( const Opie::Ui::Private::OSplitterContainer& );
void removeFromTab( QWidget* );
void changeTab();
void changeHBox();
void changeVBox();
void commonChangeBox();
QHBox *m_hbox;
OTabWidget *m_tabWidget;
OTabWidget *m_parentTab;
Orientation m_orient;
int m_size_policy;
ContainerList m_container;
QList<OSplitter> m_splitter;
QString m_icon, m_name;
struct Private;
Private *d;
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/big-screen/owidgetstack.cpp b/libopie2/opieui/big-screen/owidgetstack.cpp
index 57e97e3..a0a6355 100644
--- a/libopie2/opieui/big-screen/owidgetstack.cpp
+++ b/libopie2/opieui/big-screen/owidgetstack.cpp
@@ -1,435 +1,438 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "owidgetstack.h"
/* QT */
#include <qapplication.h>
#include <qwidgetstack.h>
-namespace {
+namespace Opie {
+namespace Ui {
const int mode_size = 330;
-}
-using namespace Opie;
+
/**
* This is the standard widget. For simple usage see the example. Normally this widget
* is the central widget of a QMainWindow.
* Use removeWidget before you delete a widget yourself. OWidgetStack does not
* yet recognize removal of children.
*
* @param parent The parent widget. It maybe 0 but then you need to take care of deletion.
* Or you use QPEApplication::showMainWidget().
* @param name Name will be passed on to QObject
* @param fl Additional window flags passed to QFrame. see @Qt::WFlags
*/
OWidgetStack::OWidgetStack( QWidget* parent, const char* name, WFlags fl)
: QFrame( parent, name, fl )
{
m_last = m_mWidget = 0;
m_forced = false;
QApplication::desktop()->installEventFilter( this );
setFontPropagation ( AllChildren );
setPalettePropagation( AllChildren );
/* sets m_mode and initializes more */
/* if you change this call change switchTop as well */
m_stack = 0;
switchStack();
}
/**
* The destructor. It deletes also all added widgets.
*
*/
OWidgetStack::~OWidgetStack() {
if (m_mode == BigScreen && !m_list.isEmpty() ) {
QMap<int, QWidget*>::Iterator it = m_list.begin();
for ( ; it != m_list.end(); ++it )
delete it.data();
}
m_list.clear();
}
/**
* return the mode of the desktop. There are currently two modes. SmallScreen
* with a normal PDA resolution and BigScreen with resolutions greater than
* 330 for width and height.
* You can also force the mode this widget is in with forceMode()
* Note that NoForce will be never returned from here
*/
enum OWidgetStack::Mode OWidgetStack::mode()const {
return m_mode;
}
/**
* You can also force one of the modes and then
* this widget stops on listening to size changes. You
* can revert to the scanning behaviour by setting mode
* to NoForce
*/
void OWidgetStack::forceMode( enum Mode mode) {
m_forced = mode != NoForce;
/* we need to see which mode we're in */
if (!m_forced ) {
if ( QApplication::desktop()->width() >=
mode_size )
mode = BigScreen;
else
mode = SmallScreen;
}
switch( mode ) {
case NoForce:
case SmallScreen:
switchStack();
break;
case BigScreen:
switchTop();
break;
}
m_mode = mode;
}
/**
* Adds a widget to the stack. The first widget added is considered
* to be the mainwindow. This is important because if Opie is in
* BigScreen mode the sizeHint of the MainWindow will be returned.
* In Small Screen the sizeHint of the QWidgetStack is returned.
* See QWidgetStack::sizeHint.
* This widget takes ownership of the widget and may even reparent.
* All windows will be hidden
*
* @param wid The QWidget to be added
* @param id An ID for the Widget. If the ID is duplicated the
last set widget will be related to the id
*
*/
void OWidgetStack::addWidget( QWidget* wid, int id) {
if (!wid)
return;
/* set our main widget */
if (!m_mWidget)
m_mWidget = wid;
m_list.insert( id, wid );
/**
* adding does not raise any widget
* But for our mainwidget we prepare
* the right position with the right parent
*/
if (m_mode == SmallScreen )
m_stack->addWidget( wid,id );
else if ( m_mWidget == wid ) {
wid->reparent(this, 0, contentsRect().topLeft() );
wid->hide();
}else {
wid->reparent(0, WType_TopLevel, QPoint(10, 10) );
wid->hide();
}
}
/**
* Remove the widget from the stack it'll be reparented to 0
* and ownership is dropped. You need to delete it.
* If the removed widget was the mainwindow consider
* to call setMainWindow.
*
* @param wid The QWidget to be removed
*/
void OWidgetStack::removeWidget( QWidget* wid) {
if (!wid)
return;
if (m_mode == SmallScreen )
m_stack->removeWidget( wid );
wid->reparent(0, 0, QPoint(0, 0) );
m_list.remove( id(wid) );
if ( wid == m_mWidget )
m_mWidget = 0;
}
#if 0
/**
* @internal_resons
*/
QSizeHint OWidgetStack::sizeHint()const {
}
/**
* @internal_reasons
*/
QSizeHint OWidgetStack::minimumSizeHint()const {
}
#endif
/**
* This function tries to find the widget with the id.
* You supplied a possible id in addWIdget. Note that not
* QWidget::winId() is used.
*
* @param id The id to search for
*
* @return The widget or null
* @see addWidget
*/
QWidget* OWidgetStack::widget( int id) const {
return m_list[id];
}
/**
* Tries to find the assigned id for the widget
* or returns -1 if no widget could be found
* @param wid The widget to look for
*/
int OWidgetStack::id( QWidget* wid)const{
if (m_list.isEmpty() )
return -1;
QMap<int, QWidget*>::ConstIterator it = m_list.begin();
for ( ; it != m_list.end(); ++it )
if ( it.data() == wid )
break;
/* if not at the end return the key */
return it == m_list.end() ? -1 : it.key();
}
/**
* This function returns the currently visible
* widget. In BigScreen mode the mainwindow
* is returned
*/
QWidget* OWidgetStack::visibleWidget()const {
if (m_mode == SmallScreen )
return m_stack->visibleWidget();
else
return m_mWidget;
}
/**
* This method raises the widget wit the specefic id.
* Note that in BigScreen mode the widget is made visible
* but the other ( previous) visible widget(s) will not
* be made invisible. If you need this use hideWidget().
*
* @param id Raise the widget with id
*/
void OWidgetStack::raiseWidget( int id) {
return raiseWidget( widget( id ) );
}
/**
* This is an overloaded function and only differs in its parameters.
* @see raiseWidget( int )
*/
void OWidgetStack::raiseWidget( QWidget* wid) {
m_last = wid;
if (m_mode == SmallScreen )
m_stack->raiseWidget( wid );
else {
int ide;
emit aboutToShow( wid );
/* if someone is connected and the widget is actually available */
if ( receivers( SIGNAL(aboutToShow(int) ) ) &&
( (ide = id( wid ) ) != -1 ) )
emit aboutToShow( ide );
/* ### FIXME PLACE THE WIDGET right */
wid->show();
}
}
/**
* This will hide the currently visible widget
* and raise the widget specified by the parameter.
* Note that this method does not use visibleWIdget but remembers
* the last raisedWidget
*/
void OWidgetStack::hideWidget( int id) {
/* hiding our main widget wouldn't be smart */
if ( m_mode == BigScreen && m_last != m_mWidget )
m_last->hide();
raiseWidget( id );
}
/**
* This is overloaded and only differs in the parameters
* it takes.
*/
void OWidgetStack::hideWidget( QWidget* wid) {
/* still not smart */
if ( m_mode == BigScreen && m_last != m_mWidget )
m_last->hide();
raiseWidget( wid );
}
bool OWidgetStack::eventFilter( QObject* obj, QEvent* e) {
qWarning(" %s %s", obj->name(), obj->className() );
if ( e->type() == QEvent::Resize ) {
QResizeEvent *res = static_cast<QResizeEvent*>( e );
QSize size = res->size();
if ( size.width() >= mode_size )
switchTop();
else
switchStack();
}
return false;
}
/**
* @internal_resons
*/
void OWidgetStack::resizeEvent( QResizeEvent* ev ) {
QFrame::resizeEvent( ev );
if (m_mode == SmallScreen )
m_stack->setGeometry( frameRect() );
else
if (m_mWidget )
m_mWidget->setGeometry( frameRect() );
}
/**
* setMainWindow gives the OWidgetStack a hint which
* window should always stay inside the stack.
* Normally the first added widget is considered to be
* the mainwindow but you can change this with this
* function.
* If in BigScreen mode the current mainwindow will be reparented
* and hidden. The position will be taken by the new one.
* If the old MainWindow was hidden the new window will
* also be hidden. If the window was visible the new mainwindow
* will be made visible too and the old one hidden. If there
* was no mainwindow it will be hidden as well.
*
* @param wid The new mainwindow
*/
void OWidgetStack::setMainWindow( QWidget* wid ) {
if (m_mode == BigScreen ) {
bool wasVisible = false;
if (m_mWidget ) {
wasVisible = !m_mWidget->isHidden();
/* hidden by default */
m_mWidget->reparent(0, WType_TopLevel, QPoint(10, 10) );
}
wid->reparent(this, 0, frameRect().topLeft() );
if (wasVisible)
wid->show();
}
m_mWidget = wid;
}
/**
* this is an overloaded member and only differs
* in the type of arguments.
* @see setMainWindow(QWidget*)
*/
void OWidgetStack::setMainWindow( int id) {
setMainWindow( widget( id ) );
}
/*
* this function switches to a stack ;)
*/
void OWidgetStack::switchStack() {
if (m_stack ) {
m_stack->setGeometry( frameRect() );
return;
}
m_mode = SmallScreen;
m_stack = new QWidgetStack(this);
connect(m_stack, SIGNAL(aboutToShow(QWidget*) ),
this, SIGNAL(aboutToShow(QWidget*) ) );
connect(m_stack, SIGNAL(aboutToShow(int) ),
this, SIGNAL(aboutToShow(int) ) );
/* now reparent the widgets... luckily QWidgetSatck does most of the work */
if (m_list.isEmpty() )
return;
QMap<int, QWidget*>::Iterator it = m_list.begin();
for ( ; it != m_list.end(); ++it )
m_stack->addWidget( it.data(), it.key() );
}
/*
* we will switch to top level mode
* reparent the list of widgets and then delete the stack
*/
void OWidgetStack::switchTop() {
m_mode = BigScreen;
/* this works because it is guaranteed that switchStack was called at least once*/
if (!m_stack && m_mWidget) {
m_mWidget->setGeometry( frameRect() );
return;
}else if (!m_stack)
return;
if (!m_list.isEmpty() ) {
QMap<int, QWidget*>::Iterator it = m_list.begin();
for ( ; it != m_list.end(); ++it ) {
/* better than reparenting twice */
if ( it.data() == m_mWidget ) {
m_mWidget->reparent(this, 0, frameRect().topLeft() );
m_mWidget->setGeometry( frameRect() );
m_mWidget->show();
}else
/* ### FIXME we need to place the widget better */
it.data()->reparent(0, WType_TopLevel, QPoint(10, 10) );
}
}
delete m_stack;
m_stack = 0;
}
+
+}
+} \ No newline at end of file
diff --git a/libopie2/opieui/big-screen/owidgetstack.h b/libopie2/opieui/big-screen/owidgetstack.h
index 53818c8..d2f9a9f 100644
--- a/libopie2/opieui/big-screen/owidgetstack.h
+++ b/libopie2/opieui/big-screen/owidgetstack.h
@@ -1,132 +1,133 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (c) 2003 hOlgAr <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OWIDGETSTACK_H
#define OWIDGETSTACK_H
/* QT*/
#include <qframe.h>
#include <qmap.h>
class QWidgetStack;
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
/**
*
* OWidgetStack is the answer to the problem of using Opie at different screen
* sizes and to have a different behaviour. Most applications use a QWidgetStack
* to supply a view on click. And by clicking the (X) you go back but this
* behaviour feels strange on bigger screens. It's ok on smaller one because
* one can't determine the difference.
* This stack reads the default out of the size of the desktop widget but
* can be forced to have either the one or the other behaviour.
* The first widget added is considered the 'main' widget and its
* sizeHint will be taking if in BigScreen mode.
* In small screen mode this widget behaves exactly like a QWidgetStack and in BigScreen
* mode it'll use the MainWindow as child of this widget and arranges the others as
* hidden top level widgets.
*
* @version 0.1
* @author hOlgAr F.
* @short Either a true stack or a list of top Level widgets
*/
class OWidgetStack : public QFrame {
Q_OBJECT
public:
enum Mode { SmallScreen, BigScreen, NoForce };
OWidgetStack( QWidget* parent, const char* name = 0, WFlags fl = 0 );
~OWidgetStack();
enum Mode mode()const;
void forceMode( enum Mode );
void addWidget( QWidget* , int );
void removeWidget( QWidget* );
// QSizeHint sizeHint()const;
// QSizeHint minimumSizeHint()const;
QWidget *widget( int )const;
int id( QWidget* )const;
QWidget* visibleWidget() const;
bool eventFilter( QObject*, QEvent* );
signals:
/**
* OWidgetStack monitors the Desktop Widget for
* size changes if it recignizes a change size it'll
* send a signal and adjust its mode. After the signal
* was emitted. During the signal a call to mode() the
* old mode will be returned. Note that if a size change happens
* but no modeChange no signal will be emitted
*
*
* @param mode The new mode of the desktop
*/
void modeChanged( enum Mode mode);
/**
* These two signals are emitted whenever we're about to
* show one of the widgets
*/
void aboutToShow( QWidget* );
void aboutToShow( int );
public slots:
void raiseWidget( int );
void raiseWidget( QWidget* );
void hideWidget( int );
void hideWidget( QWidget* );
void setMainWindow( QWidget* );
void setMainWindow( int );
protected:
void resizeEvent( QResizeEvent* );
private:
void switchStack();
void switchTop();
QMap<int, QWidget*> m_list;
QWidgetStack *m_stack;
QWidget *m_mWidget;
QWidget *m_last;
enum Mode m_mode;
bool m_forced : 1;
struct Private;
Private *d;
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/fileselector/ofiledialog.cpp b/libopie2/opieui/fileselector/ofiledialog.cpp
index e7daead..beb4d6c 100644
--- a/libopie2/opieui/fileselector/ofiledialog.cpp
+++ b/libopie2/opieui/fileselector/ofiledialog.cpp
@@ -1,222 +1,222 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/ofiledialog.h>
#include <qpe/applnk.h>
#include <qpe/config.h>
#include <qpe/qpeapplication.h>
/* QT */
#include <qfileinfo.h>
#include <qstring.h>
#include <qapplication.h>
#include <qlayout.h>
-using namespace Opie;
+using namespace Opie::Ui;
namespace
{
/*
* helper functions to load the start dir
* and to save it
* helper to extract the dir out of a file name
*/
/**
* This method will use Config( argv[0] );
* @param key The group key used
*/
QString lastUsedDir( const QString& key )
{
if ( qApp->argc() < 1 )
return QString::null;
Config cfg( QFileInfo(qApp->argv()[0]).fileName() ); // appname
cfg.setGroup( key );
return cfg.readEntry("LastDir", QPEApplication::documentDir() );
}
void saveLastDir( const QString& key, const QString& file )
{
if ( qApp->argc() < 1 )
return;
Config cfg( QFileInfo(qApp->argv()[0]).fileName() );
cfg.setGroup( key );
QFileInfo inf( file );
cfg.writeEntry("LastDir", inf.dirPath( true ) );
}
};
/**
* This constructs a modal dialog
*
* @param caption The caption of the dialog
* @param wid The parent widget
* @param mode The mode of the OFileSelector @see OFileSelector
* @param selector The selector of the OFileSelector
* @param dirName the dir or resource to start from
* @param fileName a proposed or existing filename
* @param mimetypes The mimeTypes
*/
OFileDialog::OFileDialog(const QString &caption,
QWidget *wid, int mode, int selector,
const QString &dirName,
const QString &fileName,
const QMap<QString,QStringList>& mimetypes )
: QDialog( wid, "OFileDialog", true )
{
// QVBoxLayout *lay = new QVBoxLayout(this);
//showMaximized();
QVBoxLayout *lay = new QVBoxLayout(this );
file = new OFileSelector(this , mode, selector,
dirName, fileName,
mimetypes );
lay->addWidget( file );
//lay->addWidget( file );
//showFullScreen();
setCaption( caption.isEmpty() ? tr("FileDialog") : caption );
connect(file, SIGNAL(fileSelected(const QString&) ),
this, SLOT(slotFileSelected(const QString&) ) );
connect(file, SIGNAL(ok() ),
this, SLOT(slotSelectorOk()) ) ;
connect(file, SIGNAL(dirSelected(const QString&) ), this, SLOT(slotDirSelected(const QString&) ) );
#if 0
connect(file, SIGNAL(dirSelected(const QString&) ),
this, SLOT(slotDirSelected(const QString&) ) );
#endif
}
/**
* @returns the mimetype of the selected
* currently it return QString::null
*/
QString OFileDialog::mimetype()const
{
return QString::null;
}
/**
* @return the fileName
*/
QString OFileDialog::fileName()const
{
return file->selectedName();
}
/**
* return a DocLnk to the current file
*/
DocLnk OFileDialog::selectedDocument()const
{
return file->selectedDocument();
}
/**
* This opens up a filedialog in Open mode
*
* @param selector the Selector Mode
* @param startDir Where to start from
* @param file A proposed filename
* @param mimes A list of MimeTypes
* @param wid the parent
* @param caption of the dialog if QString::null tr("Open") will be used
* @return the fileName or QString::null
*/
QString OFileDialog::getOpenFileName(int selector,
const QString &_startDir,
const QString &file,
const MimeTypes &mimes,
QWidget *wid,
const QString &caption )
{
QString ret;
QString startDir = _startDir;
if (startDir.isEmpty() )
startDir = lastUsedDir( "FileDialog-OPEN" );
OFileDialog dlg( caption.isEmpty() ? tr("Open") : caption,
wid, OFileSelector::Open, selector, startDir, file, mimes);
dlg.showMaximized();
if( dlg.exec() )
{
ret = dlg.fileName();
saveLastDir( "FileDialog-OPEN", ret );
}
return ret;
}
/**
* This opens up a file dialog in save mode
* @see getOpenFileName
*/
QString OFileDialog::getSaveFileName(int selector,
const QString &_startDir,
const QString &file,
const MimeTypes &mimes,
QWidget *wid,
const QString &caption )
{
QString ret;
QString startDir = _startDir;
if (startDir.isEmpty() )
startDir = lastUsedDir( "FileDialog-SAVE" );
OFileDialog dlg( caption.isEmpty() ? tr("Save") : caption,
wid, OFileSelector::Save, selector, startDir, file, mimes);
dlg.showMaximized();
if( dlg.exec() )
{
ret = dlg.fileName();
saveLastDir( "FileDialog-SAVE", ret );
}
return ret;
}
void OFileDialog::slotFileSelected(const QString & )
{
accept();
}
void OFileDialog::slotSelectorOk( )
{
accept();
}
void OFileDialog::slotDirSelected(const QString &dir )
{
setCaption( dir );
// if mode
//accept();
}
diff --git a/libopie2/opieui/fileselector/ofiledialog.h b/libopie2/opieui/fileselector/ofiledialog.h
index 01a599b..dfecf3d 100644
--- a/libopie2/opieui/fileselector/ofiledialog.h
+++ b/libopie2/opieui/fileselector/ofiledialog.h
@@ -1,109 +1,110 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (c) 2002 zecke <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OFILEDIALOG_H
#define OFILEDIALOG_H
/* OPIE */
#include <opie2/ofileselector.h>
/* QT */
#include <qdialog.h>
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
/**
* This class places a OFileSelector inside a QDialog.
* It provides static method for letting a user chose
* a file for either opening or saving.
* Most of the time the c'tor will not be used instead using
* the static member functions is prefered.
*
* <pre>
* QMap<QString, QStringList> mimeTypes;
* QStringList types;
* types << "text[slash]* ";
* mimeTypes.insert( tr("Text"), types );
* mimeTypes.insert( tr("All"), " * / * " ); // remove the spaces in the 2nd comment
* QString fileName= OFileDialog::getOpenFileName( OFileSelector::EXTENDED_ALL,
* "foo","bar", mimeTypes);
* </pre>
*
* @short A small QDialog swalloing a FileSelector
* @see QDialog
* @see OFileSelector
* @version 0.1-unfinished
* @author Holger Freyther ( zecke@handhelds.org )
*/
class OFileDialog : public QDialog
{
Q_OBJECT
public:
OFileDialog(const QString &caption,
QWidget *, int mode, int selector,
const QString &dirName,
const QString &fileName = QString::null,
const MimeTypes &mimetypes = MimeTypes() );
QString mimetype() const;
QString fileName() const;
DocLnk selectedDocument()const;
// static methods
static QString getOpenFileName(int selector,
const QString& startDir = QString::null,
const QString &fileName = QString::null,
const MimeTypes& mime = MimeTypes(),
QWidget *wid = 0,
const QString &caption = QString::null );
static QString getSaveFileName(int selector,
const QString& startDir = QString::null,
const QString& fileName = QString::null,
const MimeTypes& mimefilter = MimeTypes(),
QWidget *wid = 0,
const QString &caption = QString::null );
//let's OFileSelector catch up first
//static QString getExistingDirectory(const QString& startDir = QString::null,
//QWidget *parent = 0, const QString& caption = QString::null );
private:
class OFileDialogPrivate;
OFileDialogPrivate *d;
OFileSelector *file;
private slots:
void slotFileSelected( const QString & );
void slotDirSelected(const QString & );
void slotSelectorOk();
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/fileselector/ofileselector.cpp b/libopie2/opieui/fileselector/ofileselector.cpp
index 15cadd4..c4d5033 100644
--- a/libopie2/opieui/fileselector/ofileselector.cpp
+++ b/libopie2/opieui/fileselector/ofileselector.cpp
@@ -1,1166 +1,1173 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* hacky but we need to get FileSelector::filter */
#define private public
#include <qpe/fileselector.h>
#undef private
#include "ofileselector_p.h"
/* OPIE */
#include <opie2/ofileselector.h>
#include <qpe/qpeapplication.h>
#include <qpe/mimetype.h>
#include <qpe/resource.h>
#include <qpe/storage.h>
/* QT */
#include <qcombobox.h>
#include <qdir.h>
#include <qhbox.h>
#include <qheader.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qlistview.h>
#include <qpopupmenu.h>
#include <qwidgetstack.h>
#include <qregexp.h>
#include <qobjectlist.h>
-using namespace Opie;
+using namespace Opie::Ui::Private;
+namespace Opie {
+namespace Ui {
+namespace Private {
OFileViewInterface::OFileViewInterface( OFileSelector* selector )
: m_selector( selector )
{}
OFileViewInterface::~OFileViewInterface()
{}
QString OFileViewInterface::name()const
{
return m_name;
}
void OFileViewInterface::setName( const QString& name )
{
m_name = name;
}
OFileSelector* OFileViewInterface::selector()const
{
return m_selector;
}
DocLnk OFileViewInterface::selectedDocument()const
{
return DocLnk( selectedName() );
}
bool OFileViewInterface::showNew()const
{
return selector()->showNew();
}
bool OFileViewInterface::showClose()const
{
return selector()->showClose();
}
MimeTypes OFileViewInterface::mimeTypes()const
{
return selector()->mimeTypes();
}
QStringList OFileViewInterface::currentMimeType()const
{
return selector()->currentMimeType();
}
void OFileViewInterface::activate( const QString& )
{
// not implemented here
}
void OFileViewInterface::ok()
{
emit selector()->ok();
}
void OFileViewInterface::cancel()
{
emit selector()->cancel();
}
void OFileViewInterface::closeMe()
{
emit selector()->closeMe();
}
void OFileViewInterface::fileSelected( const QString& str)
{
emit selector()->fileSelected( str);
}
void OFileViewInterface::fileSelected( const DocLnk& lnk)
{
emit selector()->fileSelected( lnk );
}
void OFileViewInterface::setCurrentFileName( const QString& str )
{
selector()->m_lneEdit->setText( str );
}
QString OFileViewInterface::currentFileName()const
{
return selector()->m_lneEdit->text();
}
QString OFileViewInterface::startDirectory()const
{
return selector()->m_startDir;
}
ODocumentFileView::ODocumentFileView( OFileSelector* selector )
:OFileViewInterface( selector )
{
m_selector = 0;
setName( QObject::tr("Documents") );
}
ODocumentFileView::~ODocumentFileView()
{
}
QString ODocumentFileView::selectedName()const
{
if (!m_selector)
return QString::null;
return m_selector->selectedDocument().file();
}
QString ODocumentFileView::selectedPath()const
{
return QPEApplication::documentDir();
}
QString ODocumentFileView::directory()const
{
return selectedPath();
}
void ODocumentFileView::reread()
{
if (!m_selector)
return;
m_selector->setNewVisible( showNew() );
m_selector->setCloseVisible( showClose() );
m_selector->filter = currentMimeType().join(";");
m_selector->reread();
}
int ODocumentFileView::fileCount()const
{
if (!m_selector)
return -1;
return m_selector->fileCount();
}
DocLnk ODocumentFileView::selectedDocument()const
{
if (!m_selector)
return DocLnk();
return m_selector->selectedDocument();
}
QWidget* ODocumentFileView::widget( QWidget* parent )
{
if (!m_selector )
{
m_selector = new FileSelector(currentMimeType().join(";"), parent, "fileselector", showNew(), showClose() );
QObject::connect(m_selector, SIGNAL(fileSelected(const DocLnk&) ),
selector(), SLOT(slotDocLnkBridge(const DocLnk&) ) );
QObject::connect(m_selector, SIGNAL(closeMe() ),
selector(), SIGNAL(closeMe() ) );
QObject::connect(m_selector, SIGNAL(newSelected(const DocLnk&) ),
selector(), SIGNAL(newSelected(const DocLnk&) ) );
}
return m_selector;
}
/*
* This is the file system view used
* we use a QListView + QListViewItems for it
*/
OFileSelectorItem::OFileSelectorItem( QListView* view, const QPixmap& pixmap,
const QString& path, const QString& date,
const QString& size, const QString& dir,
bool isLocked, bool isDir )
: QListViewItem( view )
{
setPixmap(0, pixmap );
setText(1, path );
setText(2, size );
setText(3, date );
m_isDir = isDir;
m_dir = dir;
m_locked = isLocked;
}
OFileSelectorItem::~OFileSelectorItem()
{
}
bool OFileSelectorItem::isLocked()const
{
return m_locked;
}
QString OFileSelectorItem::directory()const
{
return m_dir;
}
bool OFileSelectorItem::isDir()const
{
return m_isDir;
}
QString OFileSelectorItem::path()const
{
return text( 1 );
}
QString OFileSelectorItem::key( int id, bool )const
{
QString ke;
if( id == 0 || id == 1 )
{ // name
if( m_isDir )
{
ke.append("0" );
ke.append( text(1) );
}
else
{
ke.append("1" );
ke.append( text(1) );
}
return ke;
}
else
return text( id );
}
OFileViewFileListView::OFileViewFileListView( QWidget* parent, const QString& startDir, OFileSelector* sel)
:QWidget( parent ), m_sel( sel )
{
m_all = false;
QVBoxLayout* lay = new QVBoxLayout( this );
m_currentDir = startDir;
/*
* now we add a special bar
* One Button For Up
* Home
* Doc
* And a dropdown menu with FileSystems
* FUTURE: one to change dir with lineedit
* Bookmarks
* Create Dir
*/
QHBox* box = new QHBox(this );
box->setBackgroundMode( PaletteButton );
box->setSpacing( 0 );
QToolButton *btn = new QToolButton( box );
btn->setIconSet( Resource::loadIconSet("up") );
connect(btn, SIGNAL(clicked() ),
this, SLOT( cdUP() ) );
btn = new QToolButton( box );
btn->setIconSet( Resource::loadIconSet("home") );
connect(btn, SIGNAL(clicked() ),
this, SLOT( cdHome() ) );
btn = new QToolButton( box );
btn->setIconSet( Resource::loadIconSet("DocsIcon") );
connect(btn, SIGNAL(clicked() ),
this, SLOT(cdDoc() ) );
m_btnNew = new QToolButton( box );
m_btnNew->setIconSet( Resource::loadIconSet("new") );
connect(m_btnNew, SIGNAL(clicked() ),
this, SLOT(slotNew() ) );
m_btnClose = new QToolButton( box );
m_btnClose->setIconSet( Resource::loadIconSet("close") );
connect(m_btnClose, SIGNAL(clicked() ),
selector(), SIGNAL(closeMe() ) );
btn = new QToolButton( box );
btn->setIconSet( Resource::loadIconSet("cardmon/pcmcia") );
/* let's fill device parts */
QPopupMenu* pop = new QPopupMenu(this);
connect(pop, SIGNAL( activated(int) ),
this, SLOT(slotFSActivated(int) ) );
StorageInfo storage;
const QList<FileSystem> &fs = storage.fileSystems();
QListIterator<FileSystem> it(fs);
for ( ; it.current(); ++it )
{
const QString disk = (*it)->name();
const QString path = (*it)->path();
m_dev.insert( disk, path );
pop->insertItem( disk );
}
m_fsPop = pop;
btn->setPopup( pop );
lay->addWidget( box );
m_view = new QListView( this );
m_view->installEventFilter(this);
QPEApplication::setStylusOperation( m_view->viewport(),
QPEApplication::RightOnHold);
m_view->addColumn(" " );
m_view->addColumn(tr("Name"), 135 );
m_view->addColumn(tr("Size"), -1 );
m_view->addColumn(tr("Date"), 60 );
m_view->addColumn(tr("Mime Type"), -1 );
m_view->setSorting( 1 );
m_view->setAllColumnsShowFocus( TRUE );
lay->addWidget( m_view, 1000 );
connectSlots();
}
OFileViewFileListView::~OFileViewFileListView()
{
}
void OFileViewFileListView::slotNew()
{
DocLnk lnk;
emit selector()->newSelected( lnk );
}
OFileSelectorItem* OFileViewFileListView::currentItem()const
{
QListViewItem* item = m_view->currentItem();
if (!item )
return 0l;
return static_cast<OFileSelectorItem*>(item);
}
void OFileViewFileListView::reread( bool all )
{
m_view->clear();
if (selector()->showClose() )
m_btnClose->show();
else
m_btnClose->hide();
if (selector()->showNew() )
m_btnNew->show();
else
m_btnNew->hide();
m_mimes = selector()->currentMimeType();
m_all = all;
QDir dir( m_currentDir );
if (!dir.exists() )
return;
dir.setSorting( QDir::Name | QDir::DirsFirst | QDir::Reversed );
int filter;
if (m_all )
filter = QDir::Files | QDir::Dirs | QDir::Hidden | QDir::All;
else
filter = QDir::Files | QDir::Dirs | QDir::All;
dir.setFilter( filter );
// now go through all files
const QFileInfoList *list = dir.entryInfoList();
if (!list)
{
cdUP();
return;
}
QFileInfoListIterator it( *list );
QFileInfo *fi;
while( (fi=it.current() ) )
{
if( fi->fileName() == QString::fromLatin1("..") || fi->fileName() == QString::fromLatin1(".") )
{
++it;
continue;
}
/*
* It is a symlink we try to resolve it now but don't let us attack by DOS
*
*/
if( fi->isSymLink() )
{
QString file = fi->dirPath( true ) + "/" + fi->readLink();
for( int i = 0; i<=4; i++)
{ // 5 tries to prevent dos
QFileInfo info( file );
if( !info.exists() )
{
addSymlink( fi, TRUE );
break;
}
else if( info.isDir() )
{
addDir( fi, TRUE );
break;
}
else if( info.isFile() )
{
addFile( fi, TRUE );
break;
}
else if( info.isSymLink() )
{
file = info.dirPath(true ) + "/" + info.readLink() ;
break;
}
else if( i == 4)
{ // couldn't resolve symlink add it as symlink
addSymlink( fi );
}
} // off for loop for symlink resolving
}
else if( fi->isDir() )
addDir( fi );
else if( fi->isFile() )
addFile( fi );
++it;
} // of while loop
m_view->sort();
}
int OFileViewFileListView::fileCount()const
{
return m_view->childCount();
}
QString OFileViewFileListView::currentDir()const
{
return m_currentDir;
}
OFileSelector* OFileViewFileListView::selector()
{
return m_sel;
}
bool OFileViewFileListView::eventFilter (QObject *o, QEvent *e)
{
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *k = (QKeyEvent *)e;
if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
{
slotClicked( Qt::LeftButton,m_view->currentItem(),QPoint(0,0),0);
return true;
}
}
return false;
}
void OFileViewFileListView::connectSlots()
{
connect(m_view, SIGNAL(clicked(QListViewItem*) ),
this, SLOT(slotCurrentChanged(QListViewItem*) ) );
connect(m_view, SIGNAL(mouseButtonClicked(int,QListViewItem*,const QPoint&,int) ),
this, SLOT(slotClicked(int,QListViewItem*,const QPoint&,int) ) );
}
void OFileViewFileListView::slotCurrentChanged( QListViewItem* item)
{
if (!item)
return;
#if 0
OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
if (!sel->isDir() )
{
selector()->m_lneEdit->setText( sel->text(1) );
// if in fileselector mode we will emit selected
if ( selector()->mode() == OFileSelector::FileSelector )
{
qWarning("slot Current Changed");
QStringList str = QStringList::split("->", sel->text(1) );
QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
emit selector()->fileSelected( path );
DocLnk lnk( path );
emit selector()->fileSelected( lnk );
}
}
#endif
}
void OFileViewFileListView::slotClicked(int button , QListViewItem* item, const QPoint&, int )
{
if (!item || ( button != Qt::LeftButton) )
return;
OFileSelectorItem *sel = static_cast<OFileSelectorItem*>(item);
if (!sel->isLocked() )
{
QStringList str = QStringList::split("->", sel->text(1) );
if (sel->isDir() )
{
m_currentDir = sel->directory() + "/" + str[0].stripWhiteSpace();
emit selector()->dirSelected( m_currentDir );
reread( m_all );
}
else
{ // file
qWarning("slot Clicked");
selector()->m_lneEdit->setText( str[0].stripWhiteSpace() );
QString path = sel->directory() + "/" + str[0].stripWhiteSpace();
emit selector()->fileSelected( path );
DocLnk lnk( path );
emit selector()->fileSelected( lnk );
}
} // not locked
}
void OFileViewFileListView::addFile( QFileInfo* info, bool symlink )
{
MimeType type( info->absFilePath() );
if (!compliesMime( type.id() ) )
return;
QPixmap pix = type.pixmap();
QString dir, name; bool locked;
if ( pix.isNull() )
{
QWMatrix matrix;
QPixmap pixer(Resource::loadPixmap("UnknownDocument") );
matrix.scale( .4, .4 );
pix = pixer.xForm( matrix );
}
dir = info->dirPath( true );
locked = false;
if ( symlink )
name = info->fileName() + " -> " + info->dirPath() + "/" + info->readLink();
else
{
name = info->fileName();
if ( ( (selector()->mode() == OFileSelector::Open)&& !info->isReadable() ) ||
( (selector()->mode() == OFileSelector::Save)&& !info->isWritable() ) )
{
locked = true; pix = Resource::loadPixmap("locked");
}
}
(void)new OFileSelectorItem( m_view, pix, name,
info->lastModified().toString(), QString::number( info->size() ),
dir, locked );
}
void OFileViewFileListView::addDir( QFileInfo* info, bool symlink )
{
bool locked = false; QString name; QPixmap pix;
if ( ( ( selector()->mode() == OFileSelector::Open ) && !info->isReadable() ) ||
( ( selector()->mode() == OFileSelector::Save ) && !info->isWritable() ) )
{
locked = true;
if ( symlink )
pix = Resource::loadPixmap( "opie/symlink" );
else
pix = Resource::loadPixmap( "lockedfolder" );
}
else
pix = symlink ? Resource::loadPixmap( "opie/symlink") : Resource::loadPixmap("folder");
name = symlink ? info->fileName() + " -> " + info->dirPath(true) + "/" + info->readLink() :
info->fileName();
(void)new OFileSelectorItem( m_view, pix, name,
info->lastModified().toString(),
QString::number( info->size() ),
info->dirPath( true ), locked, true );
}
void OFileViewFileListView::addSymlink( QFileInfo* , bool )
{
}
void OFileViewFileListView::cdUP()
{
QDir dir( m_currentDir );
dir.cdUp();
if (!dir.exists() )
m_currentDir = "/";
else
m_currentDir = dir.absPath();
emit selector()->dirSelected( m_currentDir );
reread( m_all );
}
void OFileViewFileListView::cdHome()
{
m_currentDir = QDir::homeDirPath();
emit selector()->dirSelected( m_currentDir );
reread( m_all );
}
void OFileViewFileListView::cdDoc()
{
m_currentDir = QPEApplication::documentDir();
emit selector()->dirSelected( m_currentDir );
reread( m_all );
}
void OFileViewFileListView::changeDir( const QString& dir )
{
m_currentDir = dir;
emit selector()->dirSelected( m_currentDir );
reread( m_all );
}
void OFileViewFileListView::slotFSActivated( int id )
{
changeDir ( m_dev[m_fsPop->text(id)] );
}
/* check if the mimetype in mime
* complies with the one which is current
*/
/*
* We've the mimetype of the file
* We need to get the stringlist of the current mimetype
*
* mime = image@slashjpeg
* QStringList = 'image@slash*'
* or QStringList = image/jpeg;image/png;application/x-ogg
* or QStringList = application/x-ogg;image@slash*;
* with all these mime filters it should get acceptes
* to do so we need to look if mime is contained inside
* the stringlist
* if it's contained return true
* if not ( I'm no RegExp expert at all ) we'll look if a '@slash*'
* is contained in the mimefilter and then we will
* look if both are equal until the '/'
*/
bool OFileViewFileListView::compliesMime( const QString& str)
{
if (str.isEmpty() || m_mimes.isEmpty() || str.stripWhiteSpace().isEmpty() )
return true;
for (QStringList::Iterator it = m_mimes.begin(); it != m_mimes.end(); ++it )
{
QRegExp reg( (*it) );
reg.setWildcard( true );
if ( str.find( reg ) != -1 )
return true;
}
return false;
}
/*
* The listView giving access to the file system!
*/
class OFileViewFileSystem : public OFileViewInterface
{
public:
OFileViewFileSystem( OFileSelector* );
~OFileViewFileSystem();
QString selectedName() const;
QString selectedPath() const;
QString directory()const;
void reread();
int fileCount()const;
QWidget* widget( QWidget* parent );
void activate( const QString& );
private:
OFileViewFileListView* m_view;
bool m_all : 1;
};
OFileViewFileSystem::OFileViewFileSystem( OFileSelector* sel)
: OFileViewInterface( sel )
{
m_view = 0;
m_all = false;
}
OFileViewFileSystem::~OFileViewFileSystem()
{
}
QString OFileViewFileSystem::selectedName()const
{
if (!m_view )
return QString::null;
QString cFN=currentFileName();
if (cFN.startsWith("/")) return cFN;
return m_view->currentDir() + "/" + cFN;
}
QString OFileViewFileSystem::selectedPath()const
{
return QString::null;
}
QString OFileViewFileSystem::directory()const
{
if (!m_view)
return QString::null;
OFileSelectorItem* item = m_view->currentItem();
if (!item )
return QString::null;
return QDir(item->directory() ).absPath();
}
void OFileViewFileSystem::reread()
{
if (!m_view)
return;
m_view->reread( m_all );
}
int OFileViewFileSystem::fileCount()const
{
if (!m_view )
return -1;
return m_view->fileCount();
}
QWidget* OFileViewFileSystem::widget( QWidget* parent )
{
if (!m_view )
{
m_view = new OFileViewFileListView( parent, startDirectory(), selector() );
}
return m_view;
}
void OFileViewFileSystem::activate( const QString& str)
{
m_all = (str != QObject::tr("Files") );
}
+
+}
/* Selector */
/**
* @short new and complete c'tor
*
* Create a OFileSelector to let the user select a file. It can
* either be used to open a file, select a save name in a dir or
* as a dropin for the FileSelector.
*
* <pre>
* QMap<QString, QStringList> mimeTypes;
* QStringList types;
* types << "text@slash* ";
* types << "audio@slash*";
* mimeTypes.insert( tr("Audio and Text"), types );
* mimeTypes.insert( tr("All"), "*@slash*);
*
* now you could create your fileselector
* </pre>
*
*
* @param parent the parent of this widget
* @param mode The mode from the enum Mode (Open,Save,FILESELECTOR)
* @param sel The selector to be used
* @param dirName The name of the dir to start int
* @param fileName The fileName placed in the fileselector lineedit
* @param mimetypes The MimeType map of used mimetypes
* @param showNew Show a New Button. Most likely to be used in the FileSelector view.
* @param showClose Show a Close Button. Most likely to be used in FileSelector view.
*
*/
OFileSelector::OFileSelector( QWidget* parent, int mode, int sel,
const QString& dirName, const QString& fileName,
const MimeTypes& mimetypes,
bool showNew, bool showClose)
:QWidget( parent, "OFileSelector" )
{
m_current = 0;
m_shNew = showNew;
m_shClose = showClose;
m_mimeType = mimetypes;
m_startDir = dirName;
m_mode = mode;
m_selector = sel;
initUI();
m_lneEdit->setText( fileName );
initMime();
initViews();
QString str;
switch ( m_selector )
{
default:
case Normal:
str = QObject::tr("Documents");
m_cmbView->setCurrentItem( 0 );
break;
case Extended:
str = QObject::tr("Files");
m_cmbView->setCurrentItem( 1 );
break;
case ExtendedAll:
str = QObject::tr("All Files");
m_cmbView->setCurrentItem( 2 );
break;
}
slotViewChange( str );
}
/**
* This a convience c'tor to just substitute the use of FileSelector
*/
OFileSelector::OFileSelector( const QString& mimeFilter, QWidget* parent, const char* name,
bool showNew, bool showClose )
: QWidget( parent, name )
{
m_current = 0;
m_shNew = showNew;
m_shClose = showClose;
m_startDir = QPEApplication::documentDir();
if (!mimeFilter.isEmpty() )
m_mimeType.insert(mimeFilter, QStringList::split(";", mimeFilter ) );
m_mode = OFileSelector::FileSelector;
m_selector = OFileSelector::Normal;
initUI();
initMime();
initViews();
m_cmbView->setCurrentItem( 0 );
slotViewChange( QObject::tr("Documents") );
}
/*
* INIT UI will set up the basic GUI
* Layout: Simple VBoxLayout
* On top a WidgetStack containing the Views...
* - List View
* - Document View
* Below we will have a Label + LineEdit
* Below we will have two ComoBoxes one for choosing the view one for
* choosing the mimetype
*/
void OFileSelector::initUI()
{
QVBoxLayout* lay = new QVBoxLayout( this );
m_stack = new QWidgetStack( this );
lay->addWidget( m_stack, 1000 );
m_nameBox = new QHBox( this );
(void)new QLabel( tr("Name:"), m_nameBox );
m_lneEdit = new QLineEdit( m_nameBox );
m_lneEdit ->installEventFilter(this);
lay->addWidget( m_nameBox );
m_cmbBox = new QHBox( this );
m_cmbView = new QComboBox( m_cmbBox );
m_cmbMime = new QComboBox( m_cmbBox );
lay->addWidget( m_cmbBox );
}
/*
* This will make sure that the return key in the name edit causes dialogs to close
*/
bool OFileSelector::eventFilter (QObject *o, QEvent *e)
{
if ( e->type() == QEvent::KeyPress )
{
QKeyEvent *k = (QKeyEvent *)e;
if ( (k->key()==Key_Enter) || (k->key()==Key_Return))
{
emit ok();
return true;
}
}
return false;
}
/*
* This will insert the MimeTypes into the Combo Box
* And also connect the changed signal
*
* AutoMimeTyping is disabled for now. It used to reparse a dir and then set available mimetypes
*/
void OFileSelector::initMime()
{
MimeTypes::Iterator it;
for ( it = m_mimeType.begin(); it != m_mimeType.end(); ++it )
{
m_cmbMime->insertItem( it.key() );
}
m_cmbMime->setCurrentItem( 0 );
connect( m_cmbMime, SIGNAL(activated(int) ),
this, SLOT(slotMimeTypeChanged() ) );
}
void OFileSelector::initViews()
{
m_cmbView->insertItem( QObject::tr("Documents") );
m_cmbView->insertItem( QObject::tr("Files") );
m_cmbView->insertItem( QObject::tr("All Files") );
connect(m_cmbView, SIGNAL(activated(const QString&) ),
this, SLOT(slotViewChange(const QString&) ) );
m_views.insert( QObject::tr("Documents"), new ODocumentFileView(this) );
/* see above why add both */
OFileViewInterface* in = new OFileViewFileSystem( this );
m_views.insert( QObject::tr("Files"), in );
m_views.insert( QObject::tr("All Files"), in );
}
/**
* d'tor
*/
OFileSelector::~OFileSelector()
{
}
/**
* Convience function for the fileselector
* make sure to delete the DocLnk
*
* @see DocLnk
* @todo remove in ODP
*/
const DocLnk* OFileSelector::selected()
{
DocLnk* lnk = new DocLnk( currentView()->selectedDocument() );
return lnk;
}
/**
*
* @return the name of the selected file
*/
QString OFileSelector::selectedName()const
{
return currentView()->selectedName();
}
/**
* @return the selected path
*/
QString OFileSelector::selectedPath()const
{
return currentView()->selectedPath();
}
/**
* @return the directory name
*/
QString OFileSelector::directory()const
{
return currentView()->directory();
}
/**
* @return a DocLnk for the selected document
*/
DocLnk OFileSelector::selectedDocument()const
{
return currentView()->selectedDocument();
}
/**
* @return the number of items for the current view
*/
int OFileSelector::fileCount()const
{
return currentView()->fileCount();
}
/**
* @return reparse the file content
*/
void OFileSelector::reread()
{
return currentView()->reread();
}
OFileViewInterface* OFileSelector::currentView()const
{
return m_current;
}
bool OFileSelector::showNew()const
{
return m_shNew;
}
bool OFileSelector::showClose()const
{
return m_shClose;
}
MimeTypes OFileSelector::mimeTypes()const
{
return m_mimeType;
}
/**
* @return the Mode of the OFileSelector
*/
int OFileSelector::mode()const
{
return m_mode;
}
/**
* @return the Selector of the OFileSelector
*/
int OFileSelector::selector()const
{
return m_selector;
}
QStringList OFileSelector::currentMimeType()const
{
return m_mimeType[m_cmbMime->currentText()];
}
void OFileSelector::slotMimeTypeChanged()
{
reread();
}
void OFileSelector::slotDocLnkBridge( const DocLnk& lnk)
{
m_lneEdit->setText( lnk.name() );
emit fileSelected( lnk );
emit fileSelected( lnk.name() );
}
void OFileSelector::slotFileBridge( const QString& str)
{
DocLnk lnk( str );
emit fileSelected( lnk );
}
void OFileSelector::slotViewChange( const QString& view )
{
OFileViewInterface* interface = m_views[view];
if (!interface)
return;
interface->activate( view );
if (m_current)
m_stack->removeWidget( m_current->widget( m_stack ) );
static int id = 1;
m_stack->addWidget( interface->widget(m_stack), id );
m_stack->raiseWidget( id );
interface->reread();
m_current = interface;
id++;
}
void OFileSelector::setNewVisible( bool b )
{
m_shNew = b;
currentView()->reread();
}
void OFileSelector::setCloseVisible( bool b )
{
m_shClose = b;
currentView()->reread();
}
void OFileSelector::setNameVisible( bool b )
{
if ( b )
m_nameBox->show();
else
m_nameBox->hide();
}
+}
+}
diff --git a/libopie2/opieui/fileselector/ofileselector.h b/libopie2/opieui/fileselector/ofileselector.h
index 7fa657b..2205963 100644
--- a/libopie2/opieui/fileselector/ofileselector.h
+++ b/libopie2/opieui/fileselector/ofileselector.h
@@ -1,219 +1,222 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (C) 2002,2003 Holger Freyther <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/*
This is based on code and ideas of
L. J. Potter ljp@llornkcor.com
Thanks a lot
*/
#ifndef OFILESELECTOR_H
#define OFILESELECTOR_H
/* OPIE */
#include <qpe/applnk.h>
/* QT */
#include <qlist.h>
#include <qwidget.h>
#include <qmap.h>
#include <qvaluelist.h>
#include <qstringlist.h>
class QLineEdit;
class QComboBox;
class QWidgetStack;
class QHBox;
typedef QMap<QString, QStringList> MimeTypes;
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
+namespace Private {
class OFileViewInterface;
class OFileViewFileListView;
+}
/**
* @short a dropin replacement for the FileSelector
*
* This class is first used insert the OFileDialog.
* It supports multiple view and mimetype filtering for now.
*
* @see OFileDialog
* @see FileSelector
* @author zecke
* @version 0.1
*/
class OFileSelector : public QWidget
{
Q_OBJECT
- friend class Opie::OFileViewInterface;
- friend class Opie::OFileViewFileListView;
+ friend class Private::OFileViewInterface;
+ friend class Private::OFileViewFileListView;
public:
/**
* The Mode of the Fileselector
* Open = Open A File
* Save = Save a File
* FILESELECTOR = As A GUI in a screen to select a file
*/
enum Mode { Open=1, Save=2, FileSelector=4, OPEN=1, SAVE=2, FILESELECTOR=4 };
// enum OldMode { OPEN=1, SAVE=2, FILESELECTOR = 4 };
/**
* Normal = The old FileSelector
* Extended = Dir View
* ExtendedAll = Dir View with all hidden files
* Default = What the vendor considers best
*/
enum Selector { Normal = 0, Extended=1, ExtendedAll =2, Default=3, NORMAL=0,EXTENDED=1, EXTENDED_ALL =2, DEFAULT=3 };
// enum OldSelector { NORMAL = 0, EXTENDED =1, EXTENDED_ALL = 2};
OFileSelector(QWidget* parent, int mode, int selector,
const QString& dirName,
const QString& fileName,
const MimeTypes& mimetypes = MimeTypes(),
bool newVisible = FALSE, bool closeVisible = FALSE );
OFileSelector(const QString& mimeFilter, QWidget* parent,
const char* name = 0, bool newVisible = TRUE, bool closeVisible = FALSE );
~OFileSelector();
const DocLnk* selected();
QString selectedName()const;
QString selectedPath()const;
QString directory()const;
DocLnk selectedDocument()const;
int fileCount()const;
void reread();
int mode()const;
int selector()const;
/**
* Set the Icon visible
* @param b Show or Hide the New Button
*/
void setNewVisible( bool b );
/**
* Set the Icon visible
*/
void setCloseVisible( bool b );
/**
* Set the Name Line visible
*/
void setNameVisible( bool b );
signals:
/**
* dirSelected is emitted whenever changed into a different dir
*/
void dirSelected( const QString& );
/**
* fileSelected is emitted when a file is selected
* it uses a DocLnk as parameter
*/
void fileSelected( const DocLnk& );
/**
* fileSelected is emitted when a file is selected
* the complete path is a parameter
*/
void fileSelected( const QString& );
/**
* Create a new File with a DocLnk
*/
void newSelected( const DocLnk& );
void closeMe();
/**
* Ok is emitted on a Qt::Key_Return or Q::Key_Enter
* in the line edit
*/
void ok();
void cancel();
/* used by the ViewInterface */
private:
bool showNew()const;
bool showClose()const;
MimeTypes mimeTypes()const;
QStringList currentMimeType()const;
private:
/* inits the Widgets */
void initUI();
/* inits the MimeType ComboBox content + connects signals and slots */
void initMime();
/* init the Views :) */
void initViews();
private:
QLineEdit* m_lneEdit; // the LineEdit for the Name
QComboBox *m_cmbView, *m_cmbMime; // two ComboBoxes to select the View and MimeType
QWidgetStack* m_stack; // our widget stack which will contain the views
- OFileViewInterface* currentView() const; // returns the currentView
- OFileViewInterface* m_current; // here is the view saved
+ Private::OFileViewInterface* currentView() const; // returns the currentView
+ Private::OFileViewInterface* m_current; // here is the view saved
bool m_shNew : 1; // should we show New?
bool m_shClose : 1; // should we show Close?
MimeTypes m_mimeType; // list of mimetypes
- QMap<QString, OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
+ QMap<QString, Private::OFileViewInterface*> m_views; // QString translated view name + ViewInterface Ptr
QHBox* m_nameBox; // the LineEdit + Label is hold here
QHBox* m_cmbBox; // this holds the two combo boxes
QString m_startDir;
int m_mode;
int m_selector;
struct Data; // used for future versions
Data *d;
private slots:
void slotMimeTypeChanged();
/* will set the text of the lineedit and emit a fileChanged signal */
void slotDocLnkBridge( const DocLnk& );
void slotFileBridge( const QString& );
void slotViewChange( const QString& );
bool eventFilter (QObject *o, QEvent *e);
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/fileselector/ofileselector_p.h b/libopie2/opieui/fileselector/ofileselector_p.h
index 818ced9..376dc98 100644
--- a/libopie2/opieui/fileselector/ofileselector_p.h
+++ b/libopie2/opieui/fileselector/ofileselector_p.h
@@ -1,191 +1,193 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (C) Holger Freyther <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OFILESELECTOR_PRIVATE_H
#define OFILESELECTOR_PRIVATE_H
/* OPIE */
#include <qpe/applnk.h>
#include <qpe/fileselector.h>
/* QT */
#include <qmap.h>
#include <qstringlist.h>
#include <qwidget.h>
#include <qlistview.h>
/*
* How to avoid having really two different objects
* for Extended and ExtendedAll
* The only difference is the Lister...
* a) static object?
* b) leave some object inside the OFileSelector which can be used?
* c) when switching views tell which view we want o have.. internally we can switch then
*
* I'll take c) -zecke
*/
typedef QMap<QString, QStringList> MimeTypes;
/* the View Interface */
class QFileInfo;
class QToolButton;
-namespace Opie
-{
-
+namespace Opie{
+namespace Ui{
class OFileSelector;
+namespace Private {
class OFileViewInterface
{
public:
OFileViewInterface( OFileSelector* selector );
virtual ~OFileViewInterface();
virtual QString selectedName()const = 0;
virtual QString selectedPath()const = 0;
virtual QString directory()const = 0;
virtual void reread() = 0;
virtual int fileCount()const = 0;
virtual DocLnk selectedDocument()const;
virtual QWidget* widget( QWidget* parent) = 0;
virtual void activate( const QString& );
QString name()const;
protected:
OFileSelector* selector()const;
void setName( const QString& );
bool showNew()const;
bool showClose()const;
MimeTypes mimeTypes()const;
QStringList currentMimeType()const;
QString startDirectory()const;
protected:
void ok();
void cancel();
void closeMe();
void fileSelected( const QString& );
void fileSelected( const DocLnk& );
void setCurrentFileName( const QString& );
QString currentFileName()const;
private:
QString m_name;
OFileSelector* m_selector;
};
/* THE Document View hosting a FileSelector*/
class ODocumentFileView : public OFileViewInterface
{
public:
ODocumentFileView( OFileSelector* selector );
~ODocumentFileView();
QString selectedName() const;
QString selectedPath() const;
QString directory() const;
void reread();
int fileCount()const;
DocLnk selectedDocument()const;
QWidget* widget( QWidget* parent );
private:
mutable FileSelector* m_selector;
};
class OFileSelectorItem : public QListViewItem
{
public:
OFileSelectorItem( QListView* view, const QPixmap& pixmap,
const QString& path, const QString& date,
const QString& size, const QString& mDir,
bool isLocked = false, bool isDir = false );
~OFileSelectorItem();
bool isLocked()const;
bool isDir()const;
QString directory()const;
QString path()const;
QString key(int id, bool )const;
private:
bool m_locked : 1;
bool m_isDir : 1;
QString m_dir;
};
class OFileViewFileListView : public QWidget
{
Q_OBJECT
public:
OFileViewFileListView( QWidget* parent, const QString& dir, OFileSelector* selector );
~OFileViewFileListView();
OFileSelectorItem* currentItem()const;
void reread( bool all = false );
int fileCount()const;
QString currentDir()const;
protected:
bool eventFilter (QObject *o, QEvent *e);
private slots:
void slotNew(); // will emit newSelected
void cdUP();
void cdHome();
void cdDoc();
void changeDir( const QString& );
void slotCurrentChanged( QListViewItem* );
void slotClicked(int, QListViewItem*, const QPoint&, int );
void slotFSActivated(int);
protected:
OFileSelector* selector();
private:
QMap<QString, QString> m_dev;
bool m_all : 1;
OFileSelector* m_sel;
QPopupMenu* m_fsPop;
bool compliesMime( const QString& );
QStringList m_mimes; // used in compy mime
QString m_currentDir;
QToolButton *m_btnNew, *m_btnClose;
void connectSlots();
void addFile( QFileInfo* info, bool symlink = FALSE );
void addDir ( QFileInfo* info, bool symlink = FALSE );
void addSymlink( QFileInfo* info, bool = FALSE );
private:
QListView* m_view;
};
-};
+}
+}
+}
#endif
diff --git a/libopie2/opieui/fileselector/ofileview.h b/libopie2/opieui/fileselector/ofileview.h
index 495401b..aaf56b1 100644
--- a/libopie2/opieui/fileselector/ofileview.h
+++ b/libopie2/opieui/fileselector/ofileview.h
@@ -1,95 +1,98 @@
/*
               =. This file is part of the OPIE Project
             .=l. Copyright (C) 2002 Holger Freyther <zecke@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This library is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This library is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OFILEVIEW_H
#define OFILEVIEW_H
/* QT */
#include <qobject.h>
#include <qwidget.h>
class QFileInfo;
class QDir;
class DocLnk;
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
+namespace Private {
/**
* A OFileView is a specialised View for the
* OFileSelector
* With a View you can chage the user visible
* representation of a OFileLister
* OFileView is just a basic interface which helps you to
* write new views
*/
class OFileView : public QWidget
{
Q_OBJECT
public:
OFileView(QWidget *widget,
const char *name );
OFileView();
virtual void addFile(const QString &mine,
QFileInfo *info,
bool isSymlink = FALSE ) = 0;
virtual void addDir (const QString &mine,
QFileInfo *info,
bool isSymlink = FALSE ) = 0;
virtual void addSymlink(const QString &mime,
QFileInfo *info,
bool isSymlink = FALSE ) = 0;
virtual void cd(const QString &path ) = 0;
signals:
void fileSelected(const QString &);
void fileSelected(const DocLnk & );
void contextMenu();
void changedDir(const QString &);
void changedDir(const QDir & );
};
class OFileViewFactory
{
// Q_OBJECT
public:
OFileViewFactory() {} ;
virtual ~OFileViewFactory() = 0;
OFileView* newView(QWidget *parent, const char *name );
QString name()const;
};
-};
+}
+}
+}
#endif
diff --git a/libopie2/opieui/oclickablelabel.cpp b/libopie2/opieui/oclickablelabel.cpp
index 4c4e581..53cb77a 100644
--- a/libopie2/opieui/oclickablelabel.cpp
+++ b/libopie2/opieui/oclickablelabel.cpp
@@ -1,173 +1,173 @@
/*
This file is part of the Opie Project
Copyright (C) Maximillian Reiß <harlekin@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/oclickablelabel.h>
-using namespace Opie;
+using namespace Opie::Ui;
/**
* This constructs the clickable ButtonLabel
*
* @param parent The parent of this label
* @param name A name of this label @see QObject
* @param fl The windowing flags
*/
OClickableLabel::OClickableLabel(QWidget* parent, const char* name, WFlags fl)
:QLabel(parent,name,fl)
{
textInverted=false;
isToggle=false;
isDown=false;
showState(false);
setFrameShadow(Sunken);
}
/**
* This method makes the label behave as a toggle button
*
* @param t Whether or not to behave like a toggle button
*/
void OClickableLabel::setToggleButton(bool t)
{
isToggle=t;
}
/**
* @internal
*/
void OClickableLabel::mousePressEvent( QMouseEvent * /*e*/ )
{
if (isToggle && isDown)
{
showState(false);
}
else
{
showState(true);
}
}
/**
* @internal
*/
void OClickableLabel::mouseReleaseEvent( QMouseEvent *e )
{
if (rect().contains(e->pos()) && isToggle) isDown=!isDown;
if (isToggle && isDown)
{
showState(true);
}
else
{
showState(false);
}
if (rect().contains(e->pos()))
{
if (isToggle)
{
emit toggled(isDown);
}
emit clicked();
}
}
/**
* @internal
*/
void OClickableLabel::mouseMoveEvent( QMouseEvent *e )
{
if (rect().contains(e->pos()))
{
if (isToggle && isDown)
{
showState(false);
}
else
{
showState(true);
}
}
else
{
if (isToggle && isDown)
{
showState(true);
}
else
{
showState(false);
}
}
}
/**
* this toggles the label and inverts the color of
* the label
* @param on
*/
void OClickableLabel::showState(bool on)
{
if (on)
{
//setFrameShape(Panel);
setInverted(true);
setBackgroundMode(PaletteHighlight);
}
else
{
//setFrameShape(NoFrame);
setInverted(false);
setBackgroundMode(PaletteBackground);
}
repaint();
}
void OClickableLabel::setInverted(bool on)
{
if ( (!textInverted && on) || (textInverted && !on) )
{
QPalette pal=palette();
QColor col=pal.color(QPalette::Normal, QColorGroup::Foreground);
col.setRgb(255-col.red(),255-col.green(),255-col.blue());
pal.setColor(QPalette::Normal, QColorGroup::Foreground, col);
setPalette(pal);
textInverted=!textInverted;
}
}
/**
* @param on if the Label is down or up
*/
void OClickableLabel::setOn(bool on)
{
isDown=on;
showState(isDown);
}
diff --git a/libopie2/opieui/oclickablelabel.h b/libopie2/opieui/oclickablelabel.h
index b224d61..90859a0 100644
--- a/libopie2/opieui/oclickablelabel.h
+++ b/libopie2/opieui/oclickablelabel.h
@@ -1,103 +1,104 @@
/*
This file is part of the Opie Project
Copyright (C) Maximillian Reiß <harlekin@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OCLICKABLELABEL_H
#define OCLICKABLELABEL_H
/* QT */
#include <qlabel.h>
-namespace Opie
-{
+namespace Opie{
+namespace Ui {
/**
* This class is a special QLabel which can behave
* as a QPushButton or QToggleButton.
* The reason to use a clickable is if you want to save space
* or you want to skip the border of a normal button
*
* <pre>
* QLabel* lbl = new OClickableLabel( parent, "PushLabel" );
* lbl->setPixmap( "config" );
* QWhatsThis::add( lbl, tr("Click here to do something") );
* </pre>
*
* @short A Label behaving as button
* @author Hakan Ardo, Maximillian Reiß ( harlekin@handhelds.org )
* @see QLabel
* @see QPushButton
* @see QToggleButton
* @version 1.0
*/
class OClickableLabel: public QLabel
{
Q_OBJECT
public:
OClickableLabel(QWidget* parent = 0, const char* name = 0,
WFlags fl = 0);
void setToggleButton(bool t);
protected:
/** @internal */
void mousePressEvent( QMouseEvent *e );
/** @internal */
void mouseReleaseEvent( QMouseEvent *e );
/** @internal */
void mouseMoveEvent( QMouseEvent *e );
public slots:
void setOn(bool on);
signals:
/**
* emitted when the labels gets clicked
*/
void clicked();
/**
* emitted when the labels gets toggled
* @param on the new new state of the label
*/
void toggled(bool on);
private:
bool isToggle : 1;
bool isDown : 1;
bool textInverted : 1;
void showState(bool on);
void setInverted(bool on);
private:
class Private;
Private *d; // private d pointer
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/odialog.cpp b/libopie2/opieui/odialog.cpp
index 4d269d4..27f8d20 100644
--- a/libopie2/opieui/odialog.cpp
+++ b/libopie2/opieui/odialog.cpp
@@ -1,55 +1,57 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/odialog.h>
#warning Make Margin and Spacing device dependend and configurable!
+using namespace Opie::Ui;
+
int ODialog::mMarginSize = 5;
int ODialog::mSpacingSize = 2;
ODialog::ODialog(QWidget *parent, const char *name, bool modal, WFlags f)
:QDialog(parent, name, modal, f)
{
// d = new ODialogPrivate();
}
int ODialog::marginHint()
{
return( mMarginSize );
}
int ODialog::spacingHint()
{
return( mSpacingSize );
}
// Placeholder for even more sophisticed things
diff --git a/libopie2/opieui/odialog.h b/libopie2/opieui/odialog.h
index ceff612..57f534c 100644
--- a/libopie2/opieui/odialog.h
+++ b/libopie2/opieui/odialog.h
@@ -1,91 +1,96 @@
/*
                This file is part of the Opie Project
              (C) 2003 Michael 'Mickey' Lauer <mickey@Vanille.de>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef ODIALOG_H
#define ODIALOG_H
class QLayoutItem;
#include <qdialog.h>
/**
* Dialog with extended nonmodal support and methods for OPIE standard
* compliance.
*
* The @ref marginHint() and @ref spacingHint() sizes shall be used
* whenever you layout the interior of a dialog. One special note. If
* you make your own action buttons (OK, Cancel etc), the space
* beteween the buttons shall be @ref spacingHint(), whereas the space
* above, below, to the right and to the left shall be @ref marginHint().
* If you add a separator line above the buttons, there shall be a
* @ref marginHint() between the buttons and the separator and a
* @ref marginHint() above the separator as well.
*
* @author Michael 'Mickey' Lauer <mickey@Vanille.de>
*/
// lets fix up Qt instead! Size does matter. -zecke
// while that may be true, reducing maintainance effort for the future does also matter -
// and I believe that maintaining a patch against QtE is more work than our classes -mml
+namespace Opie {
+namespace Ui {
+
class ODialog : public QDialog
{
Q_OBJECT
public:
/**
* Constructor.
*
* Takes the same arguments as @ref QDialog.
*/
ODialog(QWidget *parent = 0, const char *name = 0, bool modal = false, WFlags f = 0);
/**
* Return the number of pixels you shall use between a
* dialog edge and the outermost widget(s) according to the KDE standard.
**/
static int marginHint();
/**
* Return the number of pixels you shall use between
* widgets inside a dialog according to the KDE standard.
*/
static int spacingHint();
private:
static int mMarginSize;
static int mSpacingSize;
class ODialogPrivate;
ODialogPrivate *d;
};
+}
+}
#endif // ODIALOG_H
diff --git a/libopie2/opieui/ofontselector.cpp b/libopie2/opieui/ofontselector.cpp
index f93781f..b19c26e 100644
--- a/libopie2/opieui/ofontselector.cpp
+++ b/libopie2/opieui/ofontselector.cpp
@@ -1,428 +1,429 @@
/*
This file is part of the Opie Project
Copyright (C) Robert Griebl <sandman@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/ofontselector.h>
#include <qpe/fontdatabase.h>
/* QT */
#include <qlayout.h>
#include <qlistbox.h>
#include <qcombobox.h>
#include <qlabel.h>
#include <qmultilineedit.h>
-using namespace Opie;
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
+namespace Private {
class OFontSelectorPrivate
{
public:
QListBox * m_font_family_list;
QComboBox * m_font_style_list;
QComboBox * m_font_size_list;
QMultiLineEdit *m_preview;
bool m_pointbug : 1;
FontDatabase m_fdb;
};
-};
-
-namespace
-{
-
class FontListItem : public QListBoxText
{
public:
FontListItem ( const QString &t, const QStringList &styles, const QValueList<int> &sizes ) : QListBoxText()
{
m_name = t;
m_styles = styles;
m_sizes = sizes;
QString str = t;
str [0] = str [0]. upper();
setText ( str );
}
QString family() const
{
return m_name;
}
const QStringList &styles() const
{
return m_styles;
}
const QValueList<int> &sizes() const
{
return m_sizes;
}
private:
QStringList m_styles;
QValueList<int> m_sizes;
QString m_name;
};
+}
+}
+}
+
+using namespace Opie::Ui;
+using namespace Opie::Ui::Private;
static int findItemCB( QComboBox *box, const QString &str )
{
for ( int i = 0; i < box->count(); i++ )
{
if ( box->text ( i ) == str )
return i;
}
return -1;
}
-}
/* static same as anon. namespace */
static int qt_version()
{
const char *qver = qVersion();
return ( qver [0] - '0' ) * 100 + ( qver [2] - '0' ) * 10 + ( qver [4] - '0' );
}
/**
* Constructs the Selector object
* @param withpreview If a font preview should be given
* @param parent The parent of the Font Selector
* @param name The name of the object
* @param fl WidgetFlags
*/
OFontSelector::OFontSelector( bool withpreview, QWidget *parent, const char *name, WFlags fl ) : QWidget ( parent, name, fl )
{
d = new OFontSelectorPrivate();
QGridLayout *gridLayout = new QGridLayout( this, 0, 0, 4, 4 );
gridLayout->setRowStretch( 4, 10 );
d->m_font_family_list = new QListBox( this, "FontListBox" );
gridLayout->addMultiCellWidget( d->m_font_family_list, 0, 4, 0, 0 );
connect( d->m_font_family_list, SIGNAL( highlighted(int) ), this, SLOT( fontFamilyClicked(int) ) );
QLabel *label = new QLabel( tr( "Style" ), this );
gridLayout->addWidget( label, 0, 1 );
d->m_font_style_list = new QComboBox( this, "StyleListBox" );
connect( d->m_font_style_list, SIGNAL( activated(int) ), this, SLOT( fontStyleClicked(int) ) );
gridLayout->addWidget( d->m_font_style_list, 1, 1 );
label = new QLabel( tr( "Size" ), this );
gridLayout->addWidget( label, 2, 1 );
d->m_font_size_list = new QComboBox( this, "SizeListBox" );
connect( d->m_font_size_list, SIGNAL( activated(int) ),
this, SLOT( fontSizeClicked(int) ) );
gridLayout->addWidget( d->m_font_size_list, 3, 1 );
d->m_pointbug = ( qt_version() <= 233 );
if ( withpreview )
{
d->m_preview = new QMultiLineEdit ( this, "Preview" );
d->m_preview->setAlignment ( AlignCenter );
d->m_preview->setWordWrap ( QMultiLineEdit::WidgetWidth );
d->m_preview->setMargin ( 3 );
d->m_preview->setText ( tr( "The Quick Brown Fox Jumps Over The Lazy Dog" ));
gridLayout->addRowSpacing ( 5, 4 );
gridLayout->addMultiCellWidget ( d->m_preview, 6, 6, 0, 1 );
gridLayout->setRowStretch ( 6, 5 );
}
else
d->m_preview = 0;
loadFonts ( d->m_font_family_list );
}
OFontSelector::~OFontSelector()
{
delete d;
}
/**
* This methods tries to set the font
* @param f The wishes font
* @return success or failure
*/
bool OFontSelector::setSelectedFont ( const QFont &f )
{
return setSelectedFont ( f. family(), d->m_fdb. styleString ( f ), f. pointSize(), QFont::encodingName ( f. charSet()));
}
/**
* This is an overloaded method @see setSelectedFont
* @param familyStr The family of the font
* @param styleStr The style of the font
* @param sizeVal The size of font
* @param charset The charset to be used. Will be deprecated by QT3
*/
bool OFontSelector::setSelectedFont( const QString &familyStr, const QString &styleStr, int sizeVal, const QString & charset )
{
QString sizeStr = QString::number ( sizeVal );
QListBoxItem *family = d->m_font_family_list->findItem ( familyStr );
if ( !family )
family = d->m_font_family_list->findItem ( "Helvetica" );
if ( !family )
family = d->m_font_family_list->firstItem();
d->m_font_family_list->setCurrentItem ( family );
fontFamilyClicked ( d->m_font_family_list->index ( family ));
int style = findItemCB ( d->m_font_style_list, styleStr );
if ( style < 0 )
style = findItemCB ( d->m_font_style_list, "Regular" );
if ( style < 0 && d->m_font_style_list->count() > 0 )
style = 0;
d->m_font_style_list->setCurrentItem ( style );
fontStyleClicked ( style );
int size = findItemCB ( d->m_font_size_list, sizeStr );
if ( size < 0 )
size = findItemCB ( d->m_font_size_list, "10" );
if ( size < 0 && d->m_font_size_list->count() > 0 )
size = 0;
d->m_font_size_list->setCurrentItem ( size );
fontSizeClicked ( size );
return (( family ) && ( style >= 0 ) && ( size >= 0 ));
}
/**
* This method returns the name, style and size of the currently selected
* font or false if no font is selected
* @param family The font family will be written there
* @param style The style will be written there
* @param size The size will be written there
* @return success or failure
*/
bool OFontSelector::selectedFont ( QString &family, QString &style, int &size )
{
QString dummy;
return selectedFont ( family, style, size, dummy );
}
/**
* This method does return the font family or QString::null if there is
* no font item selected
* @return the font family
*/
QString OFontSelector::fontFamily() const
{
FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
return fli ? fli->family() : QString::null;
}
/**
* This method will return the style of the font or QString::null
* @return the style of the font
*/
QString OFontSelector::fontStyle() const
{
FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
int fst = d->m_font_style_list->currentItem();
return ( fli && fst >= 0 ) ? fli->styles() [fst] : QString::null;
}
/**
* This method will return the font size or 10 if no font size is available
*/
int OFontSelector::fontSize() const
{
FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
int fsi = d->m_font_size_list->currentItem();
return ( fli && fsi >= 0 ) ? fli->sizes() [fsi] : 10;
}
/**
* returns the charset of the font or QString::null
*/
QString OFontSelector::fontCharSet() const
{
FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( d->m_font_family_list->currentItem());
return fli ? d->m_fdb. charSets ( fli->family()) [0] : QString::null;
}
/**
* Overloaded member function see above
* @see selectedFont
*/
bool OFontSelector::selectedFont ( QString &family, QString &style, int &size, QString &charset )
{
int ffa = d->m_font_family_list->currentItem();
int fst = d->m_font_style_list->currentItem();
int fsi = d->m_font_size_list->currentItem();
FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
if ( fli )
{
family = fli->family();
style = fst >= 0 ? fli->styles() [fst] : QString::null;
size = fsi >= 0 ? fli->sizes() [fsi] : 10;
charset = d->m_fdb. charSets ( fli->family()) [0];
return true;
}
else
return false;
}
void OFontSelector::loadFonts ( QListBox *list )
{
QStringList f = d->m_fdb. families();
for ( QStringList::ConstIterator it = f. begin(); it != f. end(); ++it )
{
QValueList <int> ps = d->m_fdb. pointSizes ( *it );
if ( d->m_pointbug )
{
for ( QValueList <int>::Iterator it = ps. begin(); it != ps. end(); it++ )
*it /= 10;
}
list->insertItem ( new FontListItem ( *it, d->m_fdb. styles ( *it ), ps ));
}
}
void OFontSelector::fontFamilyClicked ( int index )
{
QString oldstyle = d->m_font_style_list->currentText();
QString oldsize = d->m_font_size_list->currentText();
FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( index );
d->m_font_style_list->clear();
d->m_font_style_list->insertStringList ( fli->styles());
d->m_font_style_list->setEnabled ( !fli->styles(). isEmpty());
int i;
i = findItemCB ( d->m_font_style_list, oldstyle );
if ( i < 0 )
i = findItemCB ( d->m_font_style_list, "Regular" );
if (( i < 0 ) && ( d->m_font_style_list->count() > 0 ))
i = 0;
if ( i >= 0 )
{
d->m_font_style_list->setCurrentItem ( i );
fontStyleClicked ( i );
}
d->m_font_size_list->clear();
QValueList<int> sl = fli->sizes();
for ( QValueList<int>::Iterator it = sl. begin(); it != sl. end(); ++it )
d->m_font_size_list->insertItem ( QString::number ( *it ));
i = findItemCB ( d->m_font_size_list, oldsize );
if ( i < 0 )
i = findItemCB ( d->m_font_size_list, "10" );
if (( i < 0 ) && ( d->m_font_size_list->count() > 0 ))
i = 0;
if ( i >= 0 )
{
d->m_font_size_list->setCurrentItem ( i );
fontSizeClicked ( i );
}
changeFont();
}
void OFontSelector::fontStyleClicked ( int /*index*/ )
{
changeFont();
}
void OFontSelector::fontSizeClicked ( int /*index*/ )
{
changeFont();
}
void OFontSelector::changeFont()
{
QFont f = selectedFont();
if ( d->m_preview )
d->m_preview->setFont ( f );
emit fontSelected ( f );
}
/**
* Return the selected font
*/
QFont OFontSelector::selectedFont()
{
int ffa = d->m_font_family_list->currentItem();
int fst = d->m_font_style_list->currentItem();
int fsi = d->m_font_size_list->currentItem();
FontListItem *fli = (FontListItem *) d->m_font_family_list->item ( ffa );
if ( fli )
{
return d->m_fdb. font ( fli->family(), \
fst >= 0 ? fli->styles() [fst] : QString::null, \
fsi >= 0 ? fli->sizes() [fsi] : 10, \
d->m_fdb. charSets ( fli->family()) [0] );
}
else
return QFont();
}
void OFontSelector::resizeEvent ( QResizeEvent *re )
{
if ( d->m_preview )
{
d->m_preview->setMinimumHeight ( 1 );
d->m_preview->setMaximumHeight ( 32767 );
}
QWidget::resizeEvent ( re );
if ( d->m_preview )
d->m_preview->setFixedHeight ( d->m_preview->height());
}
+
diff --git a/libopie2/opieui/ofontselector.h b/libopie2/opieui/ofontselector.h
index ad51819..1d97233 100644
--- a/libopie2/opieui/ofontselector.h
+++ b/libopie2/opieui/ofontselector.h
@@ -1,104 +1,106 @@
/*
This file is part of the Opie Project
Copyright (C) Robert Griebl <sandman@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OFONTSELECTOR_H
#define OFONTSELECTOR_H
/* QT */
#include <qwidget.h>
class QListBox;
-namespace Opie
-{
-
+namespace Opie {
+namespace Ui {
+namespace Private {
class OFontSelectorPrivate;
+}
/**
* This class lets you chose a Font out of a list of Fonts.
* It can show a preview too. This selector will use all available
* fonts
*
*
* @short A widget to select a font
* @see QWidget
* @see QFont
* @author Rober Griebl
*/
class OFontSelector : public QWidget
{
Q_OBJECT
public:
OFontSelector ( bool withpreview, QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
virtual ~OFontSelector ( );
bool selectedFont ( QString &family, QString &style, int &size );
bool selectedFont ( QString &family, QString &style, int &size, QString &charset );
QFont selectedFont ( );
bool setSelectedFont ( const QFont & );
bool setSelectedFont ( const QString &family, const QString &style, int size, const QString &charset = 0 );
QString fontFamily ( ) const;
QString fontStyle ( ) const;
int fontSize ( ) const;
QString fontCharSet ( ) const;
signals:
/**
* This signal gets emitted when a font got chosen
*/
void fontSelected ( const QFont & );
protected slots:
/** @internal */
virtual void fontFamilyClicked ( int );
/** @internal */
virtual void fontStyleClicked ( int );
/** @internal */
virtual void fontSizeClicked ( int );
protected:
virtual void resizeEvent ( QResizeEvent *re );
private:
void loadFonts ( QListBox * );
void changeFont ( );
private:
- OFontSelectorPrivate *d;
+ Private::OFontSelectorPrivate *d;
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/oimageeffect.cpp b/libopie2/opieui/oimageeffect.cpp
index 9a58bb9..be47eb2 100644
--- a/libopie2/opieui/oimageeffect.cpp
+++ b/libopie2/opieui/oimageeffect.cpp
@@ -1,427 +1,431 @@
/* This file is part of the KDE libraries
Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@kde.org>
(C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
(C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
(C) 2000 Josef Weidendorfer <weidendo@in.tum.de>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// $Id$
#include <math.h>
#include <qimage.h>
#include <stdlib.h>
#include <opie2/oimageeffect.h>
#include <opie2/odebug.h>
#define MaxRGB 255L
#define DegreesToRadians(x) ((x)*M_PI/180.0)
using namespace std;
+using namespace Opie::Core;
+
+namespace Opie {
+namespace Ui {
inline unsigned int intensityValue(unsigned int color)
{
return((unsigned int)((0.299*qRed(color) +
0.587*qGreen(color) +
0.1140000000000001*qBlue(color))));
}
//======================================================================
//
// Gradient effects
//
//======================================================================
QImage OImageEffect::gradient(const QSize &size, const QColor &ca,
const QColor &cb, GradientType eff, int ncols)
{
int rDiff, gDiff, bDiff;
int rca, gca, bca, rcb, gcb, bcb;
QImage image(size, 32);
if (size.width() == 0 || size.height() == 0) {
odebug << "WARNING: OImageEffect::gradient: invalid image" << oendl;
return image;
}
register int x, y;
rDiff = (rcb = cb.red()) - (rca = ca.red());
gDiff = (gcb = cb.green()) - (gca = ca.green());
bDiff = (bcb = cb.blue()) - (bca = ca.blue());
if( eff == VerticalGradient || eff == HorizontalGradient ){
uint *p;
uint rgb;
register int rl = rca << 16;
register int gl = gca << 16;
register int bl = bca << 16;
if( eff == VerticalGradient ) {
int rcdelta = ((1<<16) / size.height()) * rDiff;
int gcdelta = ((1<<16) / size.height()) * gDiff;
int bcdelta = ((1<<16) / size.height()) * bDiff;
for ( y = 0; y < size.height(); y++ ) {
p = (uint *) image.scanLine(y);
rl += rcdelta;
gl += gcdelta;
bl += bcdelta;
rgb = qRgb( (rl>>16), (gl>>16), (bl>>16) );
for( x = 0; x < size.width(); x++ ) {
*p = rgb;
p++;
}
}
}
else { // must be HorizontalGradient
unsigned int *o_src = (unsigned int *)image.scanLine(0);
unsigned int *src = o_src;
int rcdelta = ((1<<16) / size.width()) * rDiff;
int gcdelta = ((1<<16) / size.width()) * gDiff;
int bcdelta = ((1<<16) / size.width()) * bDiff;
for( x = 0; x < size.width(); x++) {
rl += rcdelta;
gl += gcdelta;
bl += bcdelta;
*src++ = qRgb( (rl>>16), (gl>>16), (bl>>16));
}
src = o_src;
// Believe it or not, manually copying in a for loop is faster
// than calling memcpy for each scanline (on the order of ms...).
// I think this is due to the function call overhead (mosfet).
for (y = 1; y < size.height(); ++y) {
p = (unsigned int *)image.scanLine(y);
src = o_src;
for(x=0; x < size.width(); ++x)
*p++ = *src++;
}
}
}
else {
float rfd, gfd, bfd;
float rd = rca, gd = gca, bd = bca;
unsigned char *xtable[3];
unsigned char *ytable[3];
unsigned int w = size.width(), h = size.height();
xtable[0] = new unsigned char[w];
xtable[1] = new unsigned char[w];
xtable[2] = new unsigned char[w];
ytable[0] = new unsigned char[h];
ytable[1] = new unsigned char[h];
ytable[2] = new unsigned char[h];
w*=2, h*=2;
if ( eff == DiagonalGradient || eff == CrossDiagonalGradient) {
// Diagonal dgradient code inspired by BlackBox (mosfet)
// BlackBox dgradient is (C) Brad Hughes, <bhughes@tcac.net> and
// Mike Cole <mike@mydot.com>.
rfd = (float)rDiff/w;
gfd = (float)gDiff/w;
bfd = (float)bDiff/w;
int dir;
for (x = 0; x < size.width(); x++, rd+=rfd, gd+=gfd, bd+=bfd) {
dir = eff == DiagonalGradient? x : size.width() - x - 1;
xtable[0][dir] = (unsigned char) rd;
xtable[1][dir] = (unsigned char) gd;
xtable[2][dir] = (unsigned char) bd;
}
rfd = (float)rDiff/h;
gfd = (float)gDiff/h;
bfd = (float)bDiff/h;
rd = gd = bd = 0;
for (y = 0; y < size.height(); y++, rd+=rfd, gd+=gfd, bd+=bfd) {
ytable[0][y] = (unsigned char) rd;
ytable[1][y] = (unsigned char) gd;
ytable[2][y] = (unsigned char) bd;
}
for (y = 0; y < size.height(); y++) {
unsigned int *scanline = (unsigned int *)image.scanLine(y);
for (x = 0; x < size.width(); x++) {
scanline[x] = qRgb(xtable[0][x] + ytable[0][y],
xtable[1][x] + ytable[1][y],
xtable[2][x] + ytable[2][y]);
}
}
}
else if (eff == RectangleGradient ||
eff == PyramidGradient ||
eff == PipeCrossGradient ||
eff == EllipticGradient)
{
int rSign = rDiff>0? 1: -1;
int gSign = gDiff>0? 1: -1;
int bSign = bDiff>0? 1: -1;
rfd = (float)rDiff / size.width();
gfd = (float)gDiff / size.width();
bfd = (float)bDiff / size.width();
rd = (float)rDiff/2;
gd = (float)gDiff/2;
bd = (float)bDiff/2;
for (x = 0; x < size.width(); x++, rd-=rfd, gd-=gfd, bd-=bfd)
{
xtable[0][x] = (unsigned char) abs((int)rd);
xtable[1][x] = (unsigned char) abs((int)gd);
xtable[2][x] = (unsigned char) abs((int)bd);
}
rfd = (float)rDiff/size.height();
gfd = (float)gDiff/size.height();
bfd = (float)bDiff/size.height();
rd = (float)rDiff/2;
gd = (float)gDiff/2;
bd = (float)bDiff/2;
for (y = 0; y < size.height(); y++, rd-=rfd, gd-=gfd, bd-=bfd)
{
ytable[0][y] = (unsigned char) abs((int)rd);
ytable[1][y] = (unsigned char) abs((int)gd);
ytable[2][y] = (unsigned char) abs((int)bd);
}
unsigned int rgb;
int h = (size.height()+1)>>1;
for (y = 0; y < h; y++) {
unsigned int *sl1 = (unsigned int *)image.scanLine(y);
unsigned int *sl2 = (unsigned int *)image.scanLine(QMAX(size.height()-y-1, y));
int w = (size.width()+1)>>1;
int x2 = size.width()-1;
for (x = 0; x < w; x++, x2--) {
rgb = 0;
if (eff == PyramidGradient) {
rgb = qRgb(rcb-rSign*(xtable[0][x]+ytable[0][y]),
gcb-gSign*(xtable[1][x]+ytable[1][y]),
bcb-bSign*(xtable[2][x]+ytable[2][y]));
}
if (eff == RectangleGradient) {
rgb = qRgb(rcb - rSign *
QMAX(xtable[0][x], ytable[0][y]) * 2,
gcb - gSign *
QMAX(xtable[1][x], ytable[1][y]) * 2,
bcb - bSign *
QMAX(xtable[2][x], ytable[2][y]) * 2);
}
if (eff == PipeCrossGradient) {
rgb = qRgb(rcb - rSign *
QMIN(xtable[0][x], ytable[0][y]) * 2,
gcb - gSign *
QMIN(xtable[1][x], ytable[1][y]) * 2,
bcb - bSign *
QMIN(xtable[2][x], ytable[2][y]) * 2);
}
if (eff == EllipticGradient) {
rgb = qRgb(rcb - rSign *
(int)sqrt((xtable[0][x]*xtable[0][x] +
ytable[0][y]*ytable[0][y])*2.0),
gcb - gSign *
(int)sqrt((xtable[1][x]*xtable[1][x] +
ytable[1][y]*ytable[1][y])*2.0),
bcb - bSign *
(int)sqrt((xtable[2][x]*xtable[2][x] +
ytable[2][y]*ytable[2][y])*2.0));
}
sl1[x] = sl2[x] = rgb;
sl1[x2] = sl2[x2] = rgb;
}
}
}
delete [] xtable[0];
delete [] xtable[1];
delete [] xtable[2];
delete [] ytable[0];
delete [] ytable[1];
delete [] ytable[2];
}
// dither if necessary
if (ncols && (QPixmap::defaultDepth() < 15 )) {
if ( ncols < 2 || ncols > 256 )
ncols = 3;
QColor *dPal = new QColor[ncols];
for (int i=0; i<ncols; i++) {
dPal[i].setRgb ( rca + rDiff * i / ( ncols - 1 ),
gca + gDiff * i / ( ncols - 1 ),
bca + bDiff * i / ( ncols - 1 ) );
}
dither(image, dPal, ncols);
delete [] dPal;
}
return image;
}
// -----------------------------------------------------------------------------
//CT this was (before Dirk A. Mueller's speedup changes)
// merely the same code as in the above method, but it's supposedly
// way less performant since it introduces a lot of supplementary tests
// and simple math operations for the calculus of the balance.
// (surprizingly, it isn't less performant, in the contrary :-)
// Yes, I could have merged them, but then the excellent performance of
// the balanced code would suffer with no other gain than a mere
// source code and byte code size economy.
QImage OImageEffect::unbalancedGradient(const QSize &size, const QColor &ca,
const QColor &cb, GradientType eff, int xfactor, int yfactor,
int ncols)
{
int dir; // general parameter used for direction switches
bool _xanti = false , _yanti = false;
if (xfactor < 0) _xanti = true; // negative on X direction
if (yfactor < 0) _yanti = true; // negative on Y direction
xfactor = abs(xfactor);
yfactor = abs(yfactor);
if (!xfactor) xfactor = 1;
if (!yfactor) yfactor = 1;
if (xfactor > 200 ) xfactor = 200;
if (yfactor > 200 ) yfactor = 200;
// float xbal = xfactor/5000.;
// float ybal = yfactor/5000.;
float xbal = xfactor/30./size.width();
float ybal = yfactor/30./size.height();
float rat;
int rDiff, gDiff, bDiff;
int rca, gca, bca, rcb, gcb, bcb;
QImage image(size, 32);
if (size.width() == 0 || size.height() == 0) {
odebug << "WARNING: OImageEffect::unbalancedGradient : invalid image" << oendl;
return image;
}
register int x, y;
unsigned int *scanline;
rDiff = (rcb = cb.red()) - (rca = ca.red());
gDiff = (gcb = cb.green()) - (gca = ca.green());
bDiff = (bcb = cb.blue()) - (bca = ca.blue());
if( eff == VerticalGradient || eff == HorizontalGradient){
QColor cRow;
uint *p;
uint rgbRow;
if( eff == VerticalGradient) {
for ( y = 0; y < size.height(); y++ ) {
dir = _yanti ? y : size.height() - 1 - y;
p = (uint *) image.scanLine(dir);
rat = 1 - exp( - (float)y * ybal );
cRow.setRgb( rcb - (int) ( rDiff * rat ),
gcb - (int) ( gDiff * rat ),
bcb - (int) ( bDiff * rat ) );
rgbRow = cRow.rgb();
for( x = 0; x < size.width(); x++ ) {
*p = rgbRow;
p++;
}
}
}
else {
unsigned int *src = (unsigned int *)image.scanLine(0);
for(x = 0; x < size.width(); x++ )
{
dir = _xanti ? x : size.width() - 1 - x;
rat = 1 - exp( - (float)x * xbal );
src[dir] = qRgb(rcb - (int) ( rDiff * rat ),
gcb - (int) ( gDiff * rat ),
bcb - (int) ( bDiff * rat ));
}
// Believe it or not, manually copying in a for loop is faster
// than calling memcpy for each scanline (on the order of ms...).
// I think this is due to the function call overhead (mosfet).
for(y = 1; y < size.height(); ++y)
{
scanline = (unsigned int *)image.scanLine(y);
for(x=0; x < size.width(); ++x)
scanline[x] = src[x];
}
}
}
else {
int w=size.width(), h=size.height();
unsigned char *xtable[3];
unsigned char *ytable[3];
xtable[0] = new unsigned char[w];
xtable[1] = new unsigned char[w];
xtable[2] = new unsigned char[w];
ytable[0] = new unsigned char[h];
ytable[1] = new unsigned char[h];
ytable[2] = new unsigned char[h];
if ( eff == DiagonalGradient || eff == CrossDiagonalGradient)
{
@@ -3384,385 +3388,386 @@ QImage OImageEffect::sharpen(QImage &src, double factor)
p++;
p2++;
p3++;
q++;
}
p++;
*q++=(*(cTable+(*p)));
}
}
return(dest);
}
QImage OImageEffect::emboss(QImage &src)
{
#define Emboss(weight) \
total_red+=(weight)*qRed(*s); \
total_green+=(weight)*qGreen(*s); \
total_blue+=(weight)*qBlue(*s); \
s++;
#define Emboss256(weight) \
total_red+=(weight)*qRed(*(cTable+(*s))); \
total_green+=(weight)*qGreen(*(cTable+(*s))); \
total_blue+=(weight)*qBlue(*(cTable+(*s))); \
s++;
if(src.width() < 3 || src.height() < 3)
return(src);
double total_blue, total_green, total_red;
int x, y;
unsigned int *q;
QImage dest(src.width(), src.height(), 32);
if(src.depth() > 8){ // DirectClass source image
unsigned int *p, *s;
for(y=0; y < src.height(); ++y){
p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
q = (unsigned int *)dest.scanLine(y);
// emboss this row of pixels.
*q++=(*(p+src.width()));
for(x=1; x < src.width()-1; ++x){
// compute weighted average of target pixel color components.
total_red=0.0;
total_green=0.0;
total_blue=0.0;
s=p;
Emboss(-1); Emboss(-2); Emboss( 0);
s=p+src.width();
Emboss(-2); Emboss( 0); Emboss( 2);
s=p+2*src.width();
Emboss( 0); Emboss( 2); Emboss( 1);
total_red += (MaxRGB+1)/2;
total_green += (MaxRGB+1)/2;
total_blue += (MaxRGB+1)/2;
*q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red),
(unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green),
(unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue),
255);
p++;
q++;
}
p++;
*q++=(*p);
}
}
else{ // PsudeoClass source image
unsigned char *p, *p2, *p3, *s;
unsigned int *cTable = src.colorTable();
int scanLineIdx;
for(y=0; y < src.height(); ++y){
scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
p = (unsigned char *)src.scanLine(scanLineIdx);
p2 = (unsigned char *)src.scanLine(scanLineIdx+1);
p3 = (unsigned char *)src.scanLine(scanLineIdx+2);
q = (unsigned int *)dest.scanLine(y);
// emboss this row of pixels.
*q++=(*(cTable+(*p2)));
for(x=1; x < src.width()-1; ++x){
// compute weighted average of target pixel color components.
total_red=0.0;
total_green=0.0;
total_blue=0.0;
s=p;
Emboss256(-1); Emboss256(-2); Emboss256(0);
s=p2;
Emboss256(-2); Emboss256(0); Emboss256(2);
s=p3;
Emboss256(0); Emboss256(2); Emboss256(1);
total_red += (MaxRGB+1)/2;
total_green += (MaxRGB+1)/2;
total_blue += (MaxRGB+1)/2;
*q = qRgba((unsigned char)((total_red < 0) ? 0 : (total_red > MaxRGB) ? MaxRGB : total_red),
(unsigned char)((total_green < 0) ? 0 : (total_green > MaxRGB) ? MaxRGB : total_green),
(unsigned char)((total_blue < 0) ? 0 : (total_blue > MaxRGB) ? MaxRGB : total_blue),
255);
p++;
p2++;
p3++;
q++;
}
p++;
*q++=(*(cTable+(*p)));
}
}
toGray(dest);
normalize(dest);
return(dest);
}
QImage OImageEffect::shade(QImage &src, bool color_shading, double azimuth,
double elevation)
{
struct PointInfo{
double x, y, z;
};
double distance, normal_distance, shade;
int x, y;
struct PointInfo light, normal;
unsigned int *q;
QImage dest(src.width(), src.height(), 32);
azimuth = DegreesToRadians(azimuth);
elevation = DegreesToRadians(elevation);
light.x = MaxRGB*cos(azimuth)*cos(elevation);
light.y = MaxRGB*sin(azimuth)*cos(elevation);
light.z = MaxRGB*sin(elevation);
normal.z= 2*MaxRGB; // constant Z of surface normal
if(src.depth() > 8){ // DirectClass source image
unsigned int *p, *s0, *s1, *s2;
for(y=0; y < src.height(); ++y){
p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
q = (unsigned int *)dest.scanLine(y);
// shade this row of pixels.
*q++=(*(p+src.width()));
p++;
s0 = p;
s1 = p + src.width();
s2 = p + 2*src.width();
for(x=1; x < src.width()-1; ++x){
// determine the surface normal and compute shading.
normal.x=intensityValue(*(s0-1))+intensityValue(*(s1-1))+intensityValue(*(s2-1))-
(double) intensityValue(*(s0+1))-(double) intensityValue(*(s1+1))-
(double) intensityValue(*(s2+1));
normal.y=intensityValue(*(s2-1))+intensityValue(*s2)+intensityValue(*(s2+1))-
(double) intensityValue(*(s0-1))-(double) intensityValue(*s0)-
(double) intensityValue(*(s0+1));
if((normal.x == 0) && (normal.y == 0))
shade=light.z;
else{
shade=0.0;
distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
if (distance > 0.0){
normal_distance=
normal.x*normal.x+normal.y*normal.y+normal.z*normal.z;
if(fabs(normal_distance) > 0.0000001)
shade=distance/sqrt(normal_distance);
}
}
if(!color_shading){
*q = qRgba((unsigned char)(shade),
(unsigned char)(shade),
(unsigned char)(shade),
qAlpha(*s1));
}
else{
*q = qRgba((unsigned char)((shade*qRed(*s1))/(MaxRGB+1)),
(unsigned char)((shade*qGreen(*s1))/(MaxRGB+1)),
(unsigned char)((shade*qBlue(*s1))/(MaxRGB+1)),
qAlpha(*s1));
}
++s0;
++s1;
++s2;
q++;
}
*q++=(*s1);
}
}
else{ // PsudeoClass source image
unsigned char *p, *s0, *s1, *s2;
int scanLineIdx;
unsigned int *cTable = (unsigned int *)src.colorTable();
for(y=0; y < src.height(); ++y){
scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
p = (unsigned char *)src.scanLine(scanLineIdx);
q = (unsigned int *)dest.scanLine(y);
// shade this row of pixels.
s0 = p;
s1 = (unsigned char *) src.scanLine(scanLineIdx+1);
s2 = (unsigned char *) src.scanLine(scanLineIdx+2);
*q++=(*(cTable+(*s1)));
++p;
++s0;
++s1;
++s2;
for(x=1; x < src.width()-1; ++x){
// determine the surface normal and compute shading.
normal.x=intensityValue(*(cTable+(*(s0-1))))+intensityValue(*(cTable+(*(s1-1))))+intensityValue(*(cTable+(*(s2-1))))-
(double) intensityValue(*(cTable+(*(s0+1))))-(double) intensityValue(*(cTable+(*(s1+1))))-
(double) intensityValue(*(cTable+(*(s2+1))));
normal.y=intensityValue(*(cTable+(*(s2-1))))+intensityValue(*(cTable+(*s2)))+intensityValue(*(cTable+(*(s2+1))))-
(double) intensityValue(*(cTable+(*(s0-1))))-(double) intensityValue(*(cTable+(*s0)))-
(double) intensityValue(*(cTable+(*(s0+1))));
if((normal.x == 0) && (normal.y == 0))
shade=light.z;
else{
shade=0.0;
distance=normal.x*light.x+normal.y*light.y+normal.z*light.z;
if (distance > 0.0){
normal_distance=
normal.x*normal.x+normal.y*normal.y+normal.z*normal.z;
if(fabs(normal_distance) > 0.0000001)
shade=distance/sqrt(normal_distance);
}
}
if(!color_shading){
*q = qRgba((unsigned char)(shade),
(unsigned char)(shade),
(unsigned char)(shade),
qAlpha(*(cTable+(*s1))));
}
else{
*q = qRgba((unsigned char)((shade*qRed(*(cTable+(*s1))))/(MaxRGB+1)),
(unsigned char)((shade*qGreen(*(cTable+(*s1))))/(MaxRGB+1)),
(unsigned char)((shade*qBlue(*(cTable+(*s1))))/(MaxRGB+1)),
qAlpha(*s1));
}
++s0;
++s1;
++s2;
q++;
}
*q++=(*(cTable+(*s1)));
}
}
return(dest);
}
QImage OImageEffect::blur(QImage &src, double factor)
{
#define Blur(weight) \
total_red+=(weight)*qRed(*s); \
total_green+=(weight)*qGreen(*s); \
total_blue+=(weight)*qBlue(*s); \
total_opacity+=(weight)*qAlpha(*s); \
s++;
#define Blur256(weight) \
total_red+=(weight)*qRed(*(cTable+(*s))); \
total_green+=(weight)*qGreen(*(cTable+(*s))); \
total_blue+=(weight)*qBlue(*(cTable+(*s))); \
total_opacity+=(weight)*qAlpha(*(cTable+(*s))); \
s++;
if(src.width() < 3 || src.height() < 3)
return(src);
double quantum, total_blue, total_green, total_opacity, total_red, weight;
int x, y;
unsigned int *q;
QImage dest(src.width(), src.height(), 32);
weight=((100.0-factor)/2)+1;
quantum = QMAX(weight+12.0, 1.0);
if(src.depth() > 8){ // DirectClass source image
unsigned int *p, *s;
for(y=0; y < src.height(); ++y){
p = (unsigned int *)src.scanLine(QMIN(QMAX(y-1,0),src.height()-3));
q = (unsigned int *)dest.scanLine(y);
// blur this row of pixels.
*q++=(*(p+src.width()));
for(x=1; x < src.width()-1; ++x){
// compute weighted average of target pixel color components.
total_red=0.0;
total_green=0.0;
total_blue=0.0;
total_opacity=0.0;
s=p;
Blur(1); Blur(2); Blur(1);
s=p+src.width();
Blur(2); Blur(weight); Blur(2);
s=p+2*src.width();
Blur(1); Blur(2); Blur(1);
*q = qRgba((unsigned char)((total_red+(quantum/2))/quantum),
(unsigned char)((total_green+(quantum/2))/quantum),
(unsigned char)((total_blue+(quantum/2))/quantum),
(unsigned char)((total_opacity+(quantum/2))/quantum));
p++;
q++;
}
p++;
*q++=(*p);
}
}
else{ // PsudeoClass source image
unsigned char *p, *p2, *p3, *s;
unsigned int *cTable = src.colorTable();
int scanLineIdx;
for(y=0; y < src.height(); ++y){
scanLineIdx = QMIN(QMAX(y-1,0),src.height()-3);
p = (unsigned char *)src.scanLine(scanLineIdx);
p2 = (unsigned char *)src.scanLine(scanLineIdx+1);
p3 = (unsigned char *)src.scanLine(scanLineIdx+2);
q = (unsigned int *)dest.scanLine(y);
// blur this row of pixels.
*q++=(*(cTable+(*p2)));
for(x=1; x < src.width()-1; ++x){
// compute weighted average of target pixel color components.
total_red=0.0;
total_green=0.0;
total_blue=0.0;
total_opacity=0.0;
s=p;
Blur256(1); Blur256(2); Blur256(1);
s=p2;
Blur256(2); Blur256(weight); Blur256(2);
s=p3;
Blur256(1); Blur256(2); Blur256(1);
*q = qRgba((unsigned char)((total_red+(quantum/2))/quantum),
(unsigned char)((total_green+(quantum/2))/quantum),
(unsigned char)((total_blue+(quantum/2))/quantum),
(unsigned char)((total_opacity+(quantum/2))/quantum));
p++;
p2++;
p3++;
q++;
}
p++;
*q++=(*(cTable+(*p)));
}
}
return(dest);
}
// High quality, expensive HSV contrast. You can do a faster one by just
// taking a grayscale threshold (ie: 128) and incrementing RGB color
// channels above it and decrementing those below it, but this gives much
// better results. (mosfet 12/28/01)
void OImageEffect::contrastHSV(QImage &img, bool sharpen)
{
int i, sign;
unsigned int *data;
int count;
double brightness, scale, theta;
QColor c;
int h, s, v;
sign = sharpen ? 1 : -1;
scale=0.5000000000000001;
if(img.depth() > 8){
count = img.width()*img.height();
data = (unsigned int *)img.bits();
}
else{
count = img.numColors();
data = (unsigned int *)img.colorTable();
}
for(i=0; i < count; ++i){
c.setRgb(data[i]);
c.hsv(&h, &s, &v);
brightness = v/255.0;
theta=(brightness-0.5)*M_PI;
brightness+=scale*(((scale*((sin(theta)+1.0)))-brightness)*sign);
if (brightness > 1.0)
brightness=1.0;
else
if (brightness < 0)
brightness=0.0;
v = (int)(brightness*255);
c.setHsv(h, s, v);
data[i] = qRgba(c.red(), c.green(), c.blue(), qAlpha(data[i]));
}
}
-
+}
+}
diff --git a/libopie2/opieui/oimageeffect.h b/libopie2/opieui/oimageeffect.h
index fb4d22d..4f86d5b 100644
--- a/libopie2/opieui/oimageeffect.h
+++ b/libopie2/opieui/oimageeffect.h
@@ -1,559 +1,564 @@
//FIXME: Revise for Opie - do we really need such fancy stuff on PDA's?
//FIXME: Maybe not on SL5xxx, but surely on C700 :))
//FIXME: I think we don#t need that -zecke
/* This file is part of the KDE libraries
Copyright (C) 1998, 1999, 2001, 2002 Daniel M. Duley <mosfet@interaccess.com>
(C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
(C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met:
1. Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
// $Id$
#ifndef OIMAGEEFFECT_H
#define OIMAGEEFFECT_H
class QImage;
class QSize;
class QColor;
+namespace Opie {
+namespace Ui {
/**
* This class includes various @ref QImage based graphical effects.
*
* Everything is
* static, so there is no need to create an instance of this class. You can
* just call the static methods. They are encapsulated here merely to provide
* a common namespace.
*/
class OImageEffect
{
public:
enum GradientType { VerticalGradient, HorizontalGradient,
DiagonalGradient, CrossDiagonalGradient,
PyramidGradient, RectangleGradient,
PipeCrossGradient, EllipticGradient };
enum RGBComponent { Red, Green, Blue, Gray, All };
enum Lighting {NorthLite, NWLite, WestLite, SWLite,
SouthLite, SELite, EastLite, NELite};
enum ModulationType { Intensity, Saturation, HueShift, Contrast };
enum NoiseType { UniformNoise=0, GaussianNoise, MultiplicativeGaussianNoise,
ImpulseNoise, LaplacianNoise, PoissonNoise};
enum RotateDirection{ Rotate90, Rotate180, Rotate270 };
/**
* Create a gradient from color a to color b of the specified type.
*
* @param size The desired size of the gradient.
* @param ca Color a
* @param cb Color b
* @param type The type of gradient.
* @param ncols The number of colors to use when not running on a
* truecolor display. The gradient will be dithered to this number of
* colors. Pass 0 to prevent dithering.
*/
static QImage gradient(const QSize &size, const QColor &ca,
const QColor &cb, GradientType type, int ncols=3);
/**
* Create an unbalanced gradient.
* An unbalanced gradient is a gradient where the transition from
* color a to color b is not linear, but in this case, exponential.
*
* @param size The desired size of the gradient.
* @param ca Color a
* @param cb Color b
* @param type The type of gradient.
* @param xfactor The x decay length. Use a value between -200 and 200.
* @param yfactor The y decay length.
* @param ncols The number of colors. See OPixmapEffect:gradient.
*/
static QImage unbalancedGradient(const QSize &size, const QColor &ca,
const QColor &cb, GradientType type, int xfactor = 100,
int yfactor = 100, int ncols = 3);
/**
* Blends a color into the destination image, using an opacity
* value for blending one into another. Very fast direct pixel
* manipulation is used.
*
* @author Karol Szwed (gallium@kde.org)
* @param clr source color to be blended into the destination image.
* @param dst destination image in which the source will be blended into.
* @param opacity opacity (in percent) which determines how much the source
* color will be blended into the destination image.
* @return The destination image (dst) containing the result.
*/
static QImage& blend(const QColor& clr, QImage& dst, float opacity);
/**
* Blend the src image into the destination image, using an opacity
* value for blending one into another. Very fast direct pixel
* manipulation is used.
*
* @author Karol Szwed (gallium@kde.org)
* @param src source image to be blended into the destination image.
* @param dst destination image in which the source will be blended into.
* @param opacity opacity (in percent) which determines how much the source
* image will be blended into the destination image.
* @return The destination image (dst) containing the result.
*/
static QImage& blend(QImage& src, QImage& dst, float opacity);
/**
* Blend the provided image into a background of the indicated color.
*
* @param initial_intensity this parameter takes values from -1 to 1:
* a) if positive: how much to fade the image in its
* less affected spot
* b) if negative: roughly indicates how much of the image
* remains unaffected
* @param bgnd indicates the color of the background to blend in
* @param eff lets you choose what kind of blending you like
* @param anti_dir blend in the opposite direction (makes no much sense
* with concentric blending effects)
* @param image must be 32bpp
*/
static QImage& blend(QImage &image, float initial_intensity,
const QColor &bgnd, GradientType eff,
bool anti_dir=false);
/**
* Blend an image into another one, using a gradient type
* for blending from one to another.
*
* @param image1 source1 and result of blending
* @param image2 source2 of blending
* @param gt gradient type for blending between source1 and source2
* @param xf x decay length for unbalanced gradient tpye
* @param yf y decay length for unbalanced gradient tpye
*/
static QImage& blend(QImage &image1,QImage &image2,
GradientType gt, int xf=100, int yf=100);
/**
* Blend an image into another one, using a color channel of a
* third image for the decision of blending from one to another.
*
* @param image1 Source 1 and result of blending
* @param image2 Source 2 of blending
* @param blendImage If the gray value of of pixel is 0, the result
* for this pixel is that of image1; for a gray value
* of 1, the pixel of image2 is used; for a value
* inbetween, a corresponding blending is used.
* @param channel The RBG channel to use for the blending decision.
*/
static QImage& blend(QImage &image1, QImage &image2,
QImage &blendImage, RGBComponent channel);
/**
* Blend an image into another one, using alpha in the expected way.
* @author Rik Hemsley (rikkus) <rik@kde.org>
*/
static bool blend(const QImage & upper, const QImage & lower, QImage & output);
// Not yet... static bool blend(const QImage & image1, const QImage & image2, QImage & output, const QRect & destRect);
/**
* Blend an image into another one, using alpha in the expected way and
* over coordinates @p x and @p y with respect to the lower image.
* The output is a QImage which is the @p upper image already blended
* with the @p lower one, so its size will be (in general) the same than
* @p upper instead of the same size than @p lower like the method above.
* In fact, the size of @p output is like upper's one only when it can be
* painted on lower, if there has to be some clipping, output's size will
* be the clipped area and x and y will be set to the correct up-left corner
* where the clipped rectangle begins.
*/
static bool blend(int &x, int &y, const QImage & upper, const QImage & lower, QImage & output);
/**
* Blend an image into another one, using alpha in the expected way and
* over coordinates @p x and @p y with respect to the lower image.
* The output is painted in the own @p lower image. This is an optimization
* of the blend method above provided by convenience.
*/
static bool blendOnLower(int x, int y, const QImage & upper, const QImage & lower);
/**
* Modifies the intensity of a pixmap's RGB channel component.
*
* @author Daniel M. Duley (mosfet)
* @param image The QImage to process.
* @param percent Percent value. Use a negative value to dim.
* @param channel Which channel(s) should be modified
* @return The @p image, provided for convenience.
*/
static QImage& channelIntensity(QImage &image, float percent,
RGBComponent channel);
/**
* Fade an image to a certain background color.
*
* The number of colors will not be changed.
*
* @param image The QImage to process.
* @param val The strength of the effect. 0 <= val <= 1.
* @param color The background color.
* @return Returns the @ref image(), provided for convenience.
*/
static QImage& fade(QImage &img, float val, const QColor &color);
/**
* This recolors a pixmap. The most dark color will become color a,
* the most bright one color b, and in between.
*
* @param image A QImage to process.
* @param ca Color a
* @param cb Color b
*/
static QImage& flatten(QImage &image, const QColor &ca,
const QColor &cb, int ncols=0);
/**
* Build a hash on any given @ref QImage
*
* @param image The QImage to process
* @param lite The hash faces the indicated lighting (cardinal poles).
* @param spacing How many unmodified pixels inbetween hashes.
* @return Returns the @ref image(), provided for convenience.
*/
static QImage& hash(QImage &image, Lighting lite=NorthLite,
unsigned int spacing=0);
/**
* Either brighten or dim the image by a specified percent.
* For example, .50 will modify the colors by 50%.
*
* @author Daniel M. Duley (mosfet)
* @param image The QImage to process.
* @param percent The percent value. Use a negative value to dim.
* @return Returns The @ref image(), provided for convenience.
*/
static QImage& intensity(QImage &image, float percent);
/**
* Modulate the image with a color channel of another image.
*
* @param image The QImage to modulate and result.
* @param modImage The QImage to use for modulation.
* @param reverse Invert the meaning of image/modImage; result is image!
* @param type The modulation Type to use.
* @param factor The modulation amplitude; with 0 no effect [-200;200].
* @param channel The RBG channel of image2 to use for modulation.
* @return Returns the @ref image(), provided for convenience.
*/
static QImage& modulate(QImage &image, QImage &modImage, bool reverse,
ModulationType type, int factor, RGBComponent channel);
/**
* Convert an image to grayscale.
*
* @author Daniel M. Duley (mosfet)
* @param image The @ref QImage to process.
* @param fast Set to @p true in order to use a faster but non-photographic
* quality algorithm. Appropriate for things such as toolbar icons.
* @return Returns the @ref image(), provided for convenience.
*/
static QImage& toGray(QImage &image, bool fast = false);
/**
* Desaturate an image evenly.
*
* @param image The QImage to process.
* @param desat A value between 0 and 1 setting the degree of desaturation
* @return Returns the @ref image(), provided for convenience.
*/
static QImage& desaturate(QImage &image, float desat = 0.3);
/**
* Fast, but low quality contrast of an image. Also see contrastHSV.
*
* @author Daniel M. Duley (mosfet)
* @param image The QImage to process.
* @param c A contrast value between -255 to 255.
* @return The @ref image(), provided for convenience.
*/
static QImage& contrast(QImage &image, int c);
/**
* Dither an image using Floyd-Steinberg dithering for low-color
* situations.
*
* @param image The QImage to process.
* @param palette The color palette to use
* @param size The size of the palette
* @return Returns the @ref image(), provided for convenience.
*/
static QImage& dither(QImage &img, const QColor *palette, int size);
/**
* Calculate the image for a selected image, for instance a selected icon
* on the desktop.
* @param img the QImage to select
* @param col the selected color, usually from QColorGroup::highlight().
*/
static QImage& selectedImage( QImage &img, const QColor &col );
/**
* High quality, expensive HSV contrast. You can do a faster one by just
* taking a intensity threshold (ie: 128) and incrementing RGB color
* channels above it and decrementing those below it, but this gives much
* better results.
*
* @author Daniel M. Duley (mosfet)
* @param img The QImage to process.
* @param sharpen If true sharpness is increase, (spiffed). Otherwise
* it is decreased, (dulled).
*/
static void contrastHSV(QImage &img, bool sharpen=true);
/**
* Normalizes the pixel values to span the full range of color values.
* This is a contrast enhancement technique.
* @author Daniel M. Duley (mosfet)
*/
static void normalize(QImage &img);
/**
* Performs histogram equalization on the reference
* image.
* @author Daniel M. Duley (mosfet)
*/
static void equalize(QImage &img);
/**
* Thresholds the reference image. You can also threshold images by using
* ThresholdDither in the various QPixmap/QImage convert methods, but this
* lets you specify a threshold value.
*
* @author Daniel M. Duley (mosfet)
* @param img The QImage to process.
* @param value The threshold value.
*/
static void threshold(QImage &img, unsigned int value=128);
/**
* Produces a 'solarization' effect seen when exposing a photographic
* film to light during the development process.
*
* @author Daniel M. Duley (mosfet)
* @param img The QImage to process.
* @param factor The extent of the solarization (0-99.9)
*/
static void solarize(QImage &img, double factor=50.0);
/**
* Embosses the source image. This involves highlighting the edges
* and applying various other enhancements in order to get a metal
* effect.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @return The embossed image. The original is not changed.
*/
static QImage emboss(QImage &src);
/**
* Minimizes speckle noise in the source image using the 8 hull
* algorithm.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @return The despeckled image. The original is not changed.
*/
static QImage despeckle(QImage &src);
/**
* Produces a neat little "charcoal" effect.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param factor The factor for detecting lines (0-99.0).
* @return The charcoal image. The original is not changed.
*/
static QImage charcoal(QImage &src, double factor=50.0);
/**
* Rotates the image by the specified amount
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param r The rotate direction.
* @return The rotated image. The original is not changed.
*/
static QImage rotate(QImage &src, RotateDirection r);
/**
* Scales an image using simple pixel sampling. This does not produce
* nearly as nice a result as QImage::smoothScale(), but has the
* advantage of being much faster - only a few milliseconds.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param w The new width.
* @param h The new height.
* @return The scaled image. The original is not changed.
*/
static QImage sample(QImage &src, int w, int h);
/**
* Adds noise to an image.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param type The algorithm used to generate the noise.
* @return The image with noise added. The original is not changed.
*/
static QImage addNoise(QImage &src, NoiseType type = GaussianNoise);
/**
* Blurs an image by convolving pixel neighborhoods.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param factor The percent weight to give to the center pixel.
* @return The blurred image. The original is not changed.
*/
static QImage blur(QImage &src, double factor=50.0);
/**
* Detects edges in an image using pixel neighborhoods and an edge
* detection mask.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param factor The percent weight to give to the center pixel.
* @return The image with edges detected. The original is not changed.
*/
static QImage edge(QImage &src, double factor=50.0);
/**
* Implodes an image by a specified percent.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param factor The extent of the implosion.
* @param background An RGBA value to use for the background. After the
* effect some pixels may be "empty". This value is used for those pixels.
* @return The imploded image. The original is not changed.
*/
static QImage implode(QImage &src, double factor=30.0,
unsigned int background = 0xFFFFFFFF);
/**
* Produces an oil painting effect.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param radius The radius of the pixel neighborhood used in applying the
* effect.
* @return The new image. The original is not changed.
*/
static QImage oilPaint(QImage &src, int radius=3);
/**
* Sharpens the pixels in the image using pixel neighborhoods.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param factor The percent weight to give to the center pixel.
* @return The sharpened image. The original is not changed.
*/
static QImage sharpen(QImage &src, double factor=30.0);
/**
* Randomly displaces pixels.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param amount The vicinity for choosing a random pixel to swap.
* @return The image with pixels displaced. The original is not changed.
*/
static QImage spread(QImage &src, unsigned int amount=3);
/**
* Shades the image using a distance light source.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param color_shading If true do color shading, otherwise do grayscale.
* @param azimuth Determines the light source and direction.
* @param elevation Determines the light source and direction.
* @return The shaded image. The original is not changed.
*/
static QImage shade(QImage &src, bool color_shading=true, double azimuth=30.0,
double elevation=30.0);
/**
* Swirls the image by a specified amount
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param degrees The tightness of the swirl.
* @param background An RGBA value to use for the background. After the
* effect some pixels may be "empty". This value is used for those pixels.
* @return The swirled image. The original is not changed.
*/
static QImage swirl(QImage &src, double degrees=50.0, unsigned int background =
0xFFFFFFFF);
/**
* Modifies the pixels along a sine wave.
*
* @author Daniel M. Duley (mosfet)
* @param src The QImage to process.
* @param amplitude The amplitude of the sine wave.
* @param wavelength The frequency of the sine wave.
* @return The new image. The original is not changed.
*/
static QImage wave(QImage &src, double amplitude=25.0, double frequency=150.0,
unsigned int background = 0xFFFFFFFF);
private:
/**
* Helper function to fast calc some altered (lighten, shaded) colors
*
*/
static unsigned int lHash(unsigned int c);
static unsigned int uHash(unsigned int c);
/**
* Helper function to find the nearest color to the RBG triplet
*/
static int nearestColor( int r, int g, int b, const QColor *pal, int size );
static void hull(const int x_offset, const int y_offset, const int polarity,
const int width, const int height,
unsigned int *f, unsigned int *g);
static unsigned int generateNoise(unsigned int pixel, NoiseType type);
static unsigned int interpolateColor(QImage *image, double x, double y,
unsigned int background);
};
+}
+}
+
#endif
diff --git a/libopie2/opieui/olistview.cpp b/libopie2/opieui/olistview.cpp
index 0ee2fde..38670b4 100644
--- a/libopie2/opieui/olistview.cpp
+++ b/libopie2/opieui/olistview.cpp
@@ -1,757 +1,764 @@
/*
                This file is part of the Opie Project
=. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@Vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* QT */
#include <qpixmap.h>
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/olistview.h>
+using namespace Opie::Core;
+
+
+namespace Opie {
+namespace Ui {
/*======================================================================================
* OListView
*======================================================================================*/
OListView::OListView( QWidget *parent, const char *name )
:QListView( parent, name )
{
//FIXME: get from global settings and calculate ==> see oglobalsettings.*
m_alternateBackground = QColor( 238, 246, 255 );
m_columnSeparator = QPen( QColor( 150, 160, 170 ), 0, DotLine );
m_fullWidth = true;
connect( this, SIGNAL(expanded(QListViewItem*)), SLOT(expand(QListViewItem*)));
}
OListView::~OListView()
{
}
void OListView::setFullWidth( bool fullWidth )
{
m_fullWidth = m_fullWidth;
#if QT_VERSION > 290
header()->setStretchEnabled( fullWidth, columns()-1 );
#endif
}
bool OListView::fullWidth() const
{
return m_fullWidth;
}
int OListView::addColumn( const QString& label, int width )
{
int result = QListView::addColumn( label, width );
#if QT_VERSION > 290
if (m_fullWidth) {
header()->setStretchEnabled( false, columns()-2 );
header()->setStretchEnabled( true, columns()-1 );
}
#endif
return result;
}
int OListView::addColumn( const QIconSet& iconset, const QString& label, int width )
{
int result = QListView::addColumn( iconset, label, width );
#if QT_VERSION > 290
if (m_fullWidth) {
header()->setStretchEnabled( false, columns()-2 );
header()->setStretchEnabled( true, columns()-1 );
}
#endif
return result;
}
void OListView::removeColumn( int index )
{
QListView::removeColumn(index);
#if QT_VERSION > 290
if ( m_fullWidth && index == columns() )
{
header()->setStretchEnabled( true, columns()-1 );
}
#endif
}
const QColor& OListView::alternateBackground() const
{
return m_alternateBackground;
}
void OListView::setAlternateBackground( const QColor &c )
{
m_alternateBackground = c;
repaint();
}
const QPen& OListView::columnSeparator() const
{
return m_columnSeparator;
}
void OListView::setColumnSeparator( const QPen& p )
{
m_columnSeparator = p;
repaint();
}
void OListView::expand(QListViewItem *item)
{
((OListViewItem*)item)->expand();
}
OListViewItem* OListView::childFactory()
{
return new OListViewItem( this );
}
#ifndef QT_NO_DATASTREAM
void OListView::serializeTo( QDataStream& s ) const
{
#warning Caution... the binary format is still under construction...
odebug << "storing OListView..." << oendl;
// store number of columns and the labels
s << columns();
for ( int i = 0; i < columns(); ++i )
s << columnText( i );
// calculate the number of top-level items to serialize
int items = 0;
QListViewItem* item = firstChild();
while ( item )
{
item = item->nextSibling();
items++;
}
// store number of items and the items itself
s << items;
item = firstChild();
for ( int i = 0; i < items; ++i )
{
s << *static_cast<OListViewItem*>( item );
item = item->nextSibling();
}
odebug << "OListview stored." << oendl;
}
void OListView::serializeFrom( QDataStream& s )
{
#warning Caution... the binary format is still under construction...
odebug << "loading OListView..." << oendl;
int cols;
s >> cols;
odebug << "read number of columns = " << cols << oendl;
while ( columns() < cols ) addColumn( QString::null );
for ( int i = 0; i < cols; ++i )
{
QString coltext;
s >> coltext;
qDebug( "read text '%s' for column %d", (const char*) coltext, i );
setColumnText( i, coltext );
}
int items;
s >> items;
odebug << "read number of items = " << items << oendl;
for ( int i = 0; i < items; ++i )
{
OListViewItem* item = childFactory();
s >> *item;
}
odebug << "OListView loaded." << oendl;
}
void OListView::expand()
{
odebug << "OListView::expand" << oendl;
QListViewItemIterator it( this );
while ( it.current() ) {
it.current()->setOpen( true );
++it;
}
}
void OListView::collapse()
{
odebug << "OListView::collapse" << oendl;
QListViewItemIterator it( this );
while ( it.current() ) {
it.current()->setOpen( false );
++it;
}
}
QDataStream& operator<<( QDataStream& s, const OListView& lv )
{
lv.serializeTo( s );
}
QDataStream& operator>>( QDataStream& s, OListView& lv )
{
lv.serializeFrom( s );
}
#endif // QT_NO_DATASTREAM
/*======================================================================================
* OListViewItem
*======================================================================================*/
OListViewItem::OListViewItem(QListView *parent)
: QListViewItem(parent)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent)
: QListViewItem(parent)
{
init();
}
OListViewItem::OListViewItem(QListView *parent, QListViewItem *after)
: QListViewItem(parent, after)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after)
: QListViewItem(parent, after)
{
init();
}
OListViewItem::OListViewItem(QListView *parent,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::OListViewItem(QListView *parent, QListViewItem *after,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::OListViewItem(QListViewItem *parent, QListViewItem *after,
QString label1, QString label2, QString label3, QString label4,
QString label5, QString label6, QString label7, QString label8)
: QListViewItem(parent, after, label1, label2, label3, label4, label5, label6, label7, label8)
{
init();
}
OListViewItem::~OListViewItem()
{
}
void OListViewItem::init()
{
m_known = false;
}
const QColor &OListViewItem::backgroundColor()
{
return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
listView()->viewport()->colorGroup().base();
}
bool OListViewItem::isAlternate()
{
OListView *lv = static_cast<OListView*>( listView() );
// check if the item above is an OListViewItem
OListViewItem *above = static_cast<OListViewItem*>( itemAbove() );
/*if (! itemAbove()->inherits( "OListViewItem" )) return false;*/
// check if we have a valid alternate background color
if (!(lv && lv->alternateBackground().isValid())) return false;
m_known = above ? above->m_known : true;
if (m_known)
{
m_odd = above ? !above->m_odd : false;
}
else
{
OListViewItem *item;
bool previous = true;
if (parent())
{
item = static_cast<OListViewItem *>(parent());
if ( item /*&& item->inherits( "OListViewItem" )*/ ) previous = item->m_odd;
item = static_cast<OListViewItem *>(parent()->firstChild());
/* if ( !item.inherits( "OListViewItem" ) item = 0; */
}
else
{
item = static_cast<OListViewItem *>(lv->firstChild());
}
while(item)
{
item->m_odd = previous = !previous;
item->m_known = true;
item = static_cast<OListViewItem *>(item->nextSibling());
/* if (!item.inherits( "OListViewItem" ) ) break; */
}
}
return m_odd;
}
void OListViewItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
{
QColorGroup _cg = cg;
const QPixmap *pm = listView()->viewport()->backgroundPixmap();
if (pm && !pm->isNull())
{
_cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
}
else if ( isAlternate() )
{
_cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
}
QListViewItem::paintCell( p, _cg, column, width, alignment );
//FIXME: Use styling here!
const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
p->setPen( pen );
p->drawLine( width-1, 0, width-1, height() );
}
OListViewItem* OListViewItem::childFactory()
{
return new OListViewItem( this );
}
#ifndef QT_NO_DATASTREAM
void OListViewItem::serializeTo( QDataStream& s ) const
{
#warning Caution... the binary format is still under construction...
odebug << "storing OListViewItem..." << oendl;
// store item text
for ( int i = 0; i < listView()->columns(); ++i )
{
s << text( i );
}
// calculate the number of children to serialize
int items = 0;
QListViewItem* item = firstChild();
while ( item )
{
item = item->nextSibling();
items++;
}
// store number of items and the items itself
s << items;
item = firstChild();
for ( int i = 0; i < items; ++i )
{
s << *static_cast<OListViewItem*>( item );
item = item->nextSibling();
}
odebug << "OListviewItem stored." << oendl;
}
void OListViewItem::serializeFrom( QDataStream& s )
{
#warning Caution... the binary format is still under construction...
odebug << "loading OListViewItem..." << oendl;
for ( int i = 0; i < listView()->columns(); ++i )
{
QString coltext;
s >> coltext;
qDebug( "read text '%s' for column %d", (const char*) coltext, i );
setText( i, coltext );
}
int items;
s >> items;
qDebug( "read number of items = %d", items );
for ( int i = 0; i < items; ++i )
{
OListViewItem* item = childFactory();
s >> (*item);
}
odebug << "OListViewItem loaded." << oendl;
}
QDataStream& operator<<( QDataStream& s, const OListViewItem& lvi )
{
lvi.serializeTo( s );
}
QDataStream& operator>>( QDataStream& s, OListViewItem& lvi )
{
lvi.serializeFrom( s );
}
#endif // QT_NO_DATASTREAM
/*======================================================================================
* OCheckListItem
*======================================================================================*/
OCheckListItem::OCheckListItem( QCheckListItem* parent, const QString& text, Type t )
:QCheckListItem( parent, text, t )
{
init();
}
OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, Type t)
:QCheckListItem( parent, text, t )
{
init();
}
OCheckListItem::OCheckListItem( QListView* parent, const QString& text, Type t )
:QCheckListItem( parent, text, t )
{
init();
}
OCheckListItem::OCheckListItem( QListViewItem* parent, const QString& text, const QPixmap& p )
:QCheckListItem( parent, text, p )
{
init();
}
OCheckListItem::OCheckListItem( QListView* parent, const QString& text, const QPixmap& p )
:QCheckListItem( parent, text, p )
{
init();
}
OCheckListItem::~OCheckListItem()
{
}
void OCheckListItem::init()
{
m_known = false;
}
const QColor &OCheckListItem::backgroundColor()
{
return isAlternate() ? static_cast<OListView*>(listView())->alternateBackground() :
listView()->viewport()->colorGroup().base();
}
bool OCheckListItem::isAlternate()
{
OListView *lv = static_cast<OListView*>( listView() );
// check if the item above is an OCheckListItem
OCheckListItem *above = static_cast<OCheckListItem*>( itemAbove() );
/*if (! itemAbove()->inherits( "OCheckListItem" )) return false;*/
// check if we have a valid alternate background color
if (!(lv && lv->alternateBackground().isValid())) return false;
m_known = above ? above->m_known : true;
if (m_known)
{
m_odd = above ? !above->m_odd : false;
}
else
{
OCheckListItem *item;
bool previous = true;
if (parent())
{
item = static_cast<OCheckListItem *>(parent());
if ( item /*&& item->inherits( "OCheckListItem" )*/ ) previous = item->m_odd;
item = static_cast<OCheckListItem *>(parent()->firstChild());
/* if ( !item.inherits( "OCheckListItem" ) item = 0; */
}
else
{
item = static_cast<OCheckListItem *>(lv->firstChild());
}
while(item)
{
item->m_odd = previous = !previous;
item->m_known = true;
item = static_cast<OCheckListItem *>(item->nextSibling());
/* if (!item.inherits( "OCheckListItem" ) ) break; */
}
}
return m_odd;
}
void OCheckListItem::paintCell(QPainter *p, const QColorGroup &cg, int column, int width, int alignment)
{
QColorGroup _cg = cg;
const QPixmap *pm = listView()->viewport()->backgroundPixmap();
if (pm && !pm->isNull())
{
_cg.setBrush( QColorGroup::Base, QBrush(backgroundColor(), *pm) );
p->setBrushOrigin( -listView()->contentsX(), -listView()->contentsY() );
}
else if ( isAlternate() )
{
_cg.setColor( QColorGroup::Base, static_cast<OListView*>( listView() )->alternateBackground() );
}
QCheckListItem::paintCell( p, _cg, column, width, alignment );
//FIXME: Use styling here!
const QPen& pen = static_cast<OListView*>( listView() )->columnSeparator();
p->setPen( pen );
p->drawLine( width-1, 0, width-1, height() );
}
/*======================================================================================
* ONamedListView
*======================================================================================*/
ONamedListView::ONamedListView( QWidget *parent, const char *name )
:OListView( parent, name )
{
}
ONamedListView::~ONamedListView()
{
}
void ONamedListView::addColumns( const QStringList& columns )
{
for ( QStringList::ConstIterator it = columns.begin(); it != columns.end(); ++it )
{
qDebug( "adding column %s", (const char*) *it );
addColumn( *it );
}
}
int ONamedListView::findColumn( const QString& text ) const
{
//FIXME: If used excessively, this will slow down performance of updates
//FIXME: because of the linear search over all column texts.
//FIXME: I will optimize later by using a hash map.
for ( int i = 0; i < columns(); ++i )
if ( columnText( i ) == text )
return i;
return -1;
}
ONamedListViewItem* ONamedListView::find( int column, const QString& text, int recurse ) const
{
return find( (ONamedListViewItem*) firstChild(), column, text, recurse );
}
ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, int column, const QString& text, int recurse ) const
{
ONamedListViewItem* result;
while ( item && item->text( column ) != text )
{
qDebug( "checked %s", (const char*) item->text( column ) );
if ( recurse < 0 || recurse > 0 )
{
qDebug( "recursion is %d - recursing into...", recurse );
result = find( (ONamedListViewItem*) item->firstChild(), column, text, recurse-1 );
if ( result ) return result;
}
item = (ONamedListViewItem*) item->itemBelow();
}
if ( item && item->text( column ) == text )
return item;
else
return 0;
}
ONamedListViewItem* ONamedListView::find( const QString& column, const QString& text, int recurse ) const
{
int col = findColumn( column );
if ( col != -1 )
return find( (ONamedListViewItem*) firstChild(), col, text, recurse );
else
return 0;
}
ONamedListViewItem* ONamedListView::find( ONamedListViewItem* item, const QString& column, const QString& text, int recurse ) const
{
int col = findColumn( column );
if ( col != -1 )
return find( item, col, text, recurse );
else
return 0;
}
/*======================================================================================
* ONamedListViewItem
*======================================================================================*/
ONamedListViewItem::ONamedListViewItem( QListView* parent, const QStringList& texts )
:OListViewItem( parent )
{
setText( texts );
}
ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, const QStringList& texts )
:OListViewItem( parent )
{
setText( texts );
}
ONamedListViewItem::ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts )
:OListViewItem( parent, after )
{
setText( texts );
}
ONamedListViewItem::ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts )
:OListViewItem( parent, after )
{
setText( texts );
}
ONamedListViewItem::~ONamedListViewItem()
{
}
void ONamedListViewItem::setText( const QStringList& texts )
{
int col = 0;
for ( QStringList::ConstIterator it = texts.begin(); it != texts.end(); ++it )
{
qDebug( "setting column %d = text %s", col, (const char*) *it );
OListViewItem::setText( col++, *it );
}
}
void ONamedListViewItem::setText( const QString& column, const QString& text )
{
//FIXME: If used excessively, this will slow down performance of updates
//FIXME: because of the linear search over all column texts.
//FIXME: I will optimize later by using a hash map.
int col = ( (ONamedListView*) listView() )->findColumn( column );
if ( col != -1 )
OListViewItem::setText( col, text );
else
qWarning( "ONamedListViewItem::setText(): Warning! Columntext '%s' not found.", (const char*) column );
}
ONamedListViewItem* ONamedListViewItem::find( int column, const QString& text, int recurse ) const
{
return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), column, text, recurse );
}
ONamedListViewItem* ONamedListViewItem::find( const QString& column, const QString& text, int recurse ) const
{
int col = ( (ONamedListView*) listView() )->findColumn( column );
if ( col != -1 )
return ( (ONamedListView*) listView() )->find( (ONamedListViewItem*) firstChild(), col, text, recurse );
else
return 0;
}
+}
+}
diff --git a/libopie2/opieui/olistview.h b/libopie2/opieui/olistview.h
index 59b0973..8195a62 100644
--- a/libopie2/opieui/olistview.h
+++ b/libopie2/opieui/olistview.h
@@ -1,409 +1,426 @@
/*
                This file is part of the Opie Project
=. (C) 2003-2004 Michael 'Mickey' Lauer <mickey@vanille.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OLISTVIEW_H
#define OLISTVIEW_H
#include <qcolor.h>
#include <qlistview.h>
#include <qpen.h>
#include <qdatastream.h>
#include <qstringlist.h>
+
+namespace Opie {
+namespace Ui {
class OListViewItem;
/*======================================================================================
* OListView
*======================================================================================*/
/**
* @brief A list/tree widget.
*
* A @ref QListView variant featuring visual and functional enhancements
* like an alternate background for odd rows, an autostretch mode
* for the width of the widget ( >= Qt 3 only ) and persistence capabilities.
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class OListView: public QListView
{
+ Q_OBJECT
public:
/**
* Constructor.
*
* The parameters @a parent and @a name are handled by
* @ref QListView, as usual.
*/
OListView( QWidget* parent = 0, const char* name = 0 );
/**
* Destructor.
*/
virtual ~OListView();
/**
* Let the last column fit exactly all the available width.
*/
void setFullWidth( bool fullWidth );
/**
* Returns whether the last column is set to fit the available width.
*/
bool fullWidth() const;
/**
* Reimplemented for full width support
*/
virtual int addColumn( const QString& label, int width = -1 );
/**
* Reimplemented for full width support
*/
virtual int addColumn( const QIconSet& iconset, const QString& label, int width = -1 );
/**
* Reimplemented for full width support
*/
virtual void removeColumn(int index);
/**
* Set the alternate background background @a color.
* Set to an invalid color to disable alternate colors.
* This only has an effect if the items are OListViewItems
*/
void setAlternateBackground( const QColor& color );
/**
* Sets the column separator @a pen.
*/
void setColumnSeparator( const QPen& pen );
/**
* @returns the alternate background color
*/
const QColor& alternateBackground() const;
/**
* @return the column separator pen
*/
const QPen& columnSeparator() const;
/**
* Create a list view item as child of this object
* @returns the new object
*/
virtual OListViewItem* childFactory();
#ifndef QT_NO_DATASTREAM
/**
* Serialize this object to @ref QDataStream @a stream
*/
virtual void serializeTo( QDataStream& stream ) const;
/**
* Serialize this object from a @ref QDataStream @a stream
*/
virtual void serializeFrom( QDataStream& s );
#endif
public slots:
/**
* Expand all items
*/
void expand();
/**
* Collapse all items
*/
void collapse();
protected slots:
/**
* expand the current OListViewItem
*/
void expand(QListViewItem*);
private:
QColor m_alternateBackground;
- bool m_fullWidth;
+ bool m_fullWidth : 1;
QPen m_columnSeparator;
+ class Private;
+ Private *d;
};
#ifndef QT_NO_DATASTREAM
/**
* @relates OListView
* Writes @a listview to the @a stream and returns a reference to the stream.
*/
QDataStream& operator<<( QDataStream& stream, const OListView& listview );
/**
* @relates OListView
* Reads @a listview from the @a stream and returns a reference to the stream.
*/
QDataStream& operator>>( QDataStream& stream, OListView& listview );
#endif // QT_NO_DATASTREAM
/*======================================================================================
* OListViewItem
*======================================================================================*/
class OListViewItem: public QListViewItem
{
friend class OCheckListItem;
public:
/**
* Constructors.
*/
OListViewItem( QListView * parent );
OListViewItem( QListViewItem * parent );
OListViewItem( QListView * parent, QListViewItem * after );
OListViewItem( QListViewItem * parent, QListViewItem * after );
OListViewItem( QListView * parent,
QString, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null );
OListViewItem( QListViewItem * parent,
QString, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null );
OListViewItem( QListView * parent, QListViewItem * after,
QString, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null );
OListViewItem( QListViewItem * parent, QListViewItem * after,
QString, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null );
/**
* Destructor.
*/
virtual ~OListViewItem();
/**
* @returns the background color of the list item.
*/
const QColor& backgroundColor();
/**
* @returns true, if the item is at an odd position and
* thus have to be painted with the alternate background color.
*/
bool isAlternate();
/**
* @note: Reimplemented for internal purposes - the API is not affected
*
*/
void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
/**
* Perform object initialization.
*/
void init();
/**
* create a list view item as child of this object
* @returns the new object
*/
virtual OListViewItem* childFactory();
#ifndef QT_NO_DATASTREAM
/**
* serialize this object to or from a @ref QDataStream
* @param s the stream used to serialize this object.
*/
virtual void serializeTo( QDataStream& s ) const;
/**
* serialize this object to or from a @ref QDataStream
* @param s the stream used to serialize this object.
*/
virtual void serializeFrom( QDataStream& s );
#endif
/**
* expand the the item
*/
virtual void expand(){};
private:
- bool m_known;
- bool m_odd;
+ bool m_known : 1;
+ bool m_odd : 1;
+ class Private;
+ Private *d;
};
#ifndef QT_NO_DATASTREAM
/**
* @relates QListViewItem
* Writes listview @a item and all subitems recursively to @a stream
* and returns a reference to the stream.
*/
QDataStream& operator<<( QDataStream& stream, const OListViewItem& item );
/**
* @relates QListViewItem
* Reads listview @a item from @a stream and returns a reference to the stream.
*/
QDataStream& operator>>( QDataStream& stream, OListViewItem& item );
#endif // QT_NO_DATASTREAM
/*======================================================================================
* OCheckListItem
*======================================================================================*/
class OCheckListItem : public QCheckListItem
{
public:
OCheckListItem( QCheckListItem *parent, const QString &text,
Type = Controller );
OCheckListItem( QListViewItem *parent, const QString &text,
Type = Controller );
OCheckListItem( QListView *parent, const QString &text,
Type = Controller );
OCheckListItem( QListViewItem *parent, const QString &text,
const QPixmap & );
OCheckListItem( QListView *parent, const QString &text,
const QPixmap & );
~OCheckListItem();
/**
* @returns the background color of the list item.
*/
const QColor& backgroundColor();
/**
* @returns true, if the item is at an odd position and
* thus have to be painted with the alternate background color.
*/
bool isAlternate();
/**
* @note: Reimplemented for internal purposes - the API is not affected
*
*/
void paintCell( QPainter *p, const QColorGroup &cg, int column, int width, int alignment );
/**
* Perform object initialization.
*/
void init();
private:
bool m_known;
bool m_odd;
};
/*======================================================================================
* ONamedListView
*======================================================================================*/
class ONamedListViewItem;
/**
* @brief An OListView variant with named columns.
*
* This class provides a higher-level interface to an OListView.
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class ONamedListView: public OListView
{
public:
/**
* Constructor.
*
* The parameters @a parent and @a name are handled by
* @ref OListView, as usual.
*/
ONamedListView( QWidget* parent = 0, const char* name = 0 );
/**
* Destructor.
*/
virtual ~ONamedListView();
/**
* Add a number of @a columns to the listview.
*/
virtual void addColumns( const QStringList& columns );
/**
* @returns the column index matching to @a text or -1 if not found.
*/
virtual int findColumn( const QString& text ) const;
/**
* @returns the first item which has a @a text in column @a column.
* Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
* <li>set it to 0 to search only among direct childs,
* <li>set it to 1 to search direct childs and all 1st order subchilds
* <li>set it to -1 for maximum recursion.
* </ul>
* @sa ONamedListViewItem::find()
*/
virtual ONamedListViewItem* find( ONamedListViewItem* start, int column, const QString& text, int recurse = -1 ) const;
virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
virtual ONamedListViewItem* find( ONamedListViewItem* start, const QString& column, const QString& text, int recurse = -1 ) const;
virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
+ private:
+ class Private;
+ Private *d;
};
/*======================================================================================
* ONamedListViewItem
*======================================================================================*/
/**
* @brief An OListView variant with named columns.
*
* This class provides a higher-level interface to an OListViewItem.
*
* @author Michael 'Mickey' Lauer <mickey@vanille.de>
*/
class ONamedListViewItem: public OListViewItem
{
public:
/**
* Constructor. Accepts the same parameters as a @ref OListViewItem,
* plus a @ref QStringList which holds an arbitrary number of @a texts.
*/
ONamedListViewItem( QListView* parent, const QStringList& texts );
ONamedListViewItem( QListViewItem* parent, const QStringList& texts );
ONamedListViewItem( QListView* parent, QListViewItem* after, const QStringList& texts );
ONamedListViewItem( QListViewItem* parent, QListViewItem* after, const QStringList& texts );
/**
* Destructor.
*/
virtual ~ONamedListViewItem();
/**
* Sets the text in column @a column to @a text.
* This method differs from @ref QListViewItem::setText() in that it
* accepts a string as column indicator instead of an int.
*/
virtual void setText( const QString& column, const QString& text );
/**
* Sets a number of @a texts for this item.
*/
virtual void setText( const QStringList& texts );
/**
* @returns the first child which has a @a text in column @a column.
* Set @a recurse to indicate how much subchild levels to search, e.g.<ul>
* <li>set it to 0 to search only among direct childs,
* <li>set it to 1 to search direct childs and all 1st order subchilds
* <li>set it to -1 for maximum recursion.
* </ul>
* @sa ONamedListView::find()
*/
virtual ONamedListViewItem* find( int column, const QString& text, int recurse = -1 ) const;
virtual ONamedListViewItem* find( const QString& column, const QString& text, int recurse = -1 ) const;
-};
+ private:
+ class Private;
+ Private *d;
+
+};
+}
+}
#endif // OLISTVIEW_H
diff --git a/libopie2/opieui/opieui.pro b/libopie2/opieui/opieui.pro
index 1be8db5..e895edc 100644
--- a/libopie2/opieui/opieui.pro
+++ b/libopie2/opieui/opieui.pro
@@ -1,66 +1,63 @@
TEMPLATE = lib
CONFIG += qt warn_on debug
DESTDIR = $(OPIEDIR)/lib
HEADERS = oclickablelabel.h \
odialog.h \
ofontselector.h \
oimageeffect.h \
olistview.h \
- omessagebox.h \
opixmapeffect.h \
opopupmenu.h \
opixmapprovider.h \
- oresource.h \
oselector.h \
oseparator.h \
otabinfo.h \
otabbar.h \
otabwidget.h \
otaskbarapplet.h \
oticker.h \
otimepicker.h \
oversatileview.h \
oversatileviewitem.h \
owait.h
SOURCES = oclickablelabel.cpp \
odialog.cpp \
ofontselector.cpp \
oimageeffect.cpp \
olistview.cpp \
opixmapeffect.cpp \
opopupmenu.cpp \
opixmapprovider.cpp \
- oresource.cpp \
oselector.cpp \
oseparator.cpp \
otabbar.cpp \
otabwidget.cpp \
otaskbarapplet.cpp \
oticker.cpp \
otimepicker.cpp \
oversatileview.cpp \
oversatileviewitem.cpp \
owait.cpp
include ( big-screen/big-screen.pro )
include ( fileselector/fileselector.pro )
INTERFACES = otimepickerbase.ui
TARGET = opieui2
VERSION = 1.8.5
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lopiecore2
!contains( platform, x11 ) {
include ( $(OPIEDIR)/include.pro )
}
contains( platform, x11 ) {
LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
}
diff --git a/libopie2/opieui/opixmapeffect.cpp b/libopie2/opieui/opixmapeffect.cpp
index 05f851d..794c7b2 100644
--- a/libopie2/opieui/opixmapeffect.cpp
+++ b/libopie2/opieui/opixmapeffect.cpp
@@ -1,328 +1,330 @@
/* This file is part of the KDE libraries
Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
(C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
(C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
*/
// $Id$
/* QT */
#include <qimage.h>
#include <qpainter.h>
/* OPIE */
#include <opie2/opixmapeffect.h>
#include <opie2/oimageeffect.h>
+
+using namespace Opie::Ui;
//======================================================================
//
// Gradient effects
//
//======================================================================
OPixmap& OPixmapEffect::gradient(OPixmap &pixmap, const QColor &ca,
const QColor &cb, GradientType eff, int ncols)
{
if(pixmap.depth() > 8 &&
(eff == VerticalGradient || eff == HorizontalGradient)) {
int rDiff, gDiff, bDiff;
int rca, gca, bca /*, rcb, gcb, bcb*/;
register int x, y;
rDiff = (/*rcb = */ cb.red()) - (rca = ca.red());
gDiff = (/*gcb = */ cb.green()) - (gca = ca.green());
bDiff = (/*bcb = */ cb.blue()) - (bca = ca.blue());
register int rl = rca << 16;
register int gl = gca << 16;
register int bl = bca << 16;
int rcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * rDiff;
int gcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * gDiff;
int bcdelta = ((1<<16) / (eff == VerticalGradient ? pixmap.height() : pixmap.width())) * bDiff;
QPainter p(&pixmap);
// these for-loops could be merged, but the if's in the inner loop
// would make it slow
switch(eff) {
case VerticalGradient:
for ( y = 0; y < pixmap.height(); y++ ) {
rl += rcdelta;
gl += gcdelta;
bl += bcdelta;
p.setPen(QColor(rl>>16, gl>>16, bl>>16));
p.drawLine(0, y, pixmap.width()-1, y);
}
break;
case HorizontalGradient:
for( x = 0; x < pixmap.width(); x++) {
rl += rcdelta;
gl += gcdelta;
bl += bcdelta;
p.setPen(QColor(rl>>16, gl>>16, bl>>16));
p.drawLine(x, 0, x, pixmap.height()-1);
}
break;
default:
;
}
}
else {
QImage image = OImageEffect::gradient(pixmap.size(), ca, cb,
(OImageEffect::GradientType) eff, ncols);
pixmap.convertFromImage(image);
}
return pixmap;
}
// -----------------------------------------------------------------------------
OPixmap& OPixmapEffect::unbalancedGradient(OPixmap &pixmap, const QColor &ca,
const QColor &cb, GradientType eff, int xfactor, int yfactor,
int ncols)
{
QImage image = OImageEffect::unbalancedGradient(pixmap.size(), ca, cb,
(OImageEffect::GradientType) eff,
xfactor, yfactor, ncols);
pixmap.convertFromImage(image);
return pixmap;
}
//======================================================================
//
// Intensity effects
//
//======================================================================
OPixmap& OPixmapEffect::intensity(OPixmap &pixmap, float percent)
{
QImage image = pixmap.convertToImage();
OImageEffect::intensity(image, percent);
pixmap.convertFromImage(image);
return pixmap;
}
// -----------------------------------------------------------------------------
OPixmap& OPixmapEffect::channelIntensity(OPixmap &pixmap, float percent,
RGBComponent channel)
{
QImage image = pixmap.convertToImage();
OImageEffect::channelIntensity(image, percent,
(OImageEffect::RGBComponent) channel);
pixmap.convertFromImage(image);
return pixmap;
}
//======================================================================
//
// Blend effects
//
//======================================================================
OPixmap& OPixmapEffect::blend(OPixmap &pixmap, float initial_intensity,
const QColor &bgnd, GradientType eff,
bool anti_dir, int ncols)
{
QImage image = pixmap.convertToImage();
if (image.depth() <=8)
image = image.convertDepth(32); //Sloww..
OImageEffect::blend(image, initial_intensity, bgnd,
(OImageEffect::GradientType) eff, anti_dir);
unsigned int tmp;
if(pixmap.depth() <= 8 ) {
if ( ncols < 2 || ncols > 256 )
ncols = 3;
QColor *dPal = new QColor[ncols];
for (int i=0; i<ncols; i++) {
tmp = 0 + 255 * i / ( ncols - 1 );
dPal[i].setRgb ( tmp, tmp, tmp );
}
OImageEffect::dither(image, dPal, ncols);
pixmap.convertFromImage(image);
delete [] dPal;
}
else
pixmap.convertFromImage(image);
return pixmap;
}
//======================================================================
//
// Hash effects
//
//======================================================================
OPixmap& OPixmapEffect::hash(OPixmap &pixmap, Lighting lite,
unsigned int spacing, int ncols)
{
QImage image = pixmap.convertToImage();
OImageEffect::hash(image, (OImageEffect::Lighting) lite, spacing);
unsigned int tmp;
if(pixmap.depth() <= 8 ) {
if ( ncols < 2 || ncols > 256 )
ncols = 3;
QColor *dPal = new QColor[ncols];
for (int i=0; i<ncols; i++) {
tmp = 0 + 255 * i / ( ncols - 1 );
dPal[i].setRgb ( tmp, tmp, tmp );
}
OImageEffect::dither(image, dPal, ncols);
pixmap.convertFromImage(image);
delete [] dPal;
}
else
pixmap.convertFromImage(image);
return pixmap;
}
//======================================================================
//
// Pattern effects
//
//======================================================================
#if 0
void OPixmapEffect::pattern(OPixmap &pixmap, const QColor &ca,
const QColor &cb, unsigned pat[8])
{
QImage img = pattern(pixmap.size(), ca, cb, pat);
pixmap.convertFromImage(img);
}
#endif
// -----------------------------------------------------------------------------
OPixmap OPixmapEffect::pattern(const OPixmap& pmtile, QSize size,
const QColor &ca, const QColor &cb, int ncols)
{
if (pmtile.depth() > 8)
ncols = 0;
QImage img = pmtile.convertToImage();
OImageEffect::flatten(img, ca, cb, ncols);
OPixmap pixmap;
pixmap.convertFromImage(img);
return OPixmapEffect::createTiled(pixmap, size);
}
// -----------------------------------------------------------------------------
OPixmap OPixmapEffect::createTiled(const OPixmap& pixmap, QSize size)
{
OPixmap pix;
QPainter p(&pix);
p.drawTiledPixmap(0, 0, size.width(), size.height(), pixmap);
return pix;
}
//======================================================================
//
// Fade effects
//
//======================================================================
OPixmap& OPixmapEffect::fade(OPixmap &pixmap, double val, const QColor &color)
{
QImage img = pixmap.convertToImage();
OImageEffect::fade(img, val, color);
pixmap.convertFromImage(img);
return pixmap;
}
// -----------------------------------------------------------------------------
OPixmap& OPixmapEffect::toGray(OPixmap &pixmap, bool fast)
{
QImage img = pixmap.convertToImage();
OImageEffect::toGray(img, fast);
pixmap.convertFromImage(img);
return pixmap;
}
// -----------------------------------------------------------------------------
OPixmap& OPixmapEffect::desaturate(OPixmap &pixmap, float desat)
{
QImage img = pixmap.convertToImage();
OImageEffect::desaturate(img, desat);
pixmap.convertFromImage(img);
return pixmap;
}
// -----------------------------------------------------------------------------
OPixmap& OPixmapEffect::contrast(OPixmap &pixmap, int c)
{
QImage img = pixmap.convertToImage();
OImageEffect::contrast(img, c);
pixmap.convertFromImage(img);
return pixmap;
}
//======================================================================
//
// Dither effects
//
//======================================================================
// -----------------------------------------------------------------------------
OPixmap& OPixmapEffect::dither(OPixmap &pixmap, const QColor *palette, int size)
{
QImage img = pixmap.convertToImage();
OImageEffect::dither(img, palette, size);
pixmap.convertFromImage(img);
return pixmap;
}
//======================================================================
//
// Other effects
//
//======================================================================
OPixmap OPixmapEffect::selectedPixmap( const OPixmap &pix, const QColor &col )
{
QImage img = pix.convertToImage();
OImageEffect::selectedImage(img, col);
OPixmap outPix;
outPix.convertFromImage(img);
return outPix;
}
diff --git a/libopie2/opieui/opixmapeffect.h b/libopie2/opieui/opixmapeffect.h
index 283fe2d..b780f9f 100644
--- a/libopie2/opieui/opixmapeffect.h
+++ b/libopie2/opieui/opixmapeffect.h
@@ -1,215 +1,219 @@
/* This file is part of the KDE libraries
Copyright (C) 1998, 1999 Christian Tibirna <ctibirna@total.net>
(C) 1998, 1999 Daniel M. Duley <mosfet@kde.org>
(C) 1998, 1999 Dirk A. Mueller <mueller@kde.org>
*/
// $Id$
#ifndef __OPIXMAP_EFFECT_H
#define __OPIXMAP_EFFECT_H
#include <qsize.h>
typedef QPixmap OPixmap;
class QColor;
+
+namespace Opie {
+namespace Ui {
/**
* This class includes various pixmap-based graphical effects.
*
* Everything is
* static, so there is no need to create an instance of this class. You can
* just call the static methods. They are encapsulated here merely to provide
* a common namespace.
*/
class OPixmapEffect
{
public:
enum GradientType { VerticalGradient, HorizontalGradient,
DiagonalGradient, CrossDiagonalGradient,
PyramidGradient, RectangleGradient,
PipeCrossGradient, EllipticGradient };
enum RGBComponent { Red, Green, Blue };
enum Lighting {NorthLite, NWLite, WestLite, SWLite,
SouthLite, SELite, EastLite, NELite};
/**
* Creates a gradient from color a to color b of the specified type.
*
* @param pixmap The pixmap to process.
* @param ca Color a.
* @param cb Color b.
* @param type The type of gradient.
* @param ncols The number of colors to use when not running on a
* truecolor display. The gradient will be dithered to this number of
* colors. Pass 0 to prevent dithering.
* @return Returns the generated pixmap, for convenience.
*/
static OPixmap& gradient(OPixmap& pixmap, const QColor &ca, const QColor &cb,
GradientType type, int ncols=3);
/**
* Creates an unbalanced gradient.
*
* An unbalanced gradient is a gradient where the transition from
* color a to color b is not linear, but in this case, exponential.
*
* @param pixmap The pixmap that should be written.
* @param ca Color a.
* @param cb Color b.
* @param type The type of gradient.
* @param xfactor The x decay length. Use a value between -200 and 200.
* @param yfactor The y decay length.
* @param ncols The number of colors. See #gradient.
* @return The generated pixmap, for convencience.
*/
static OPixmap& unbalancedGradient(OPixmap& pixmap, const QColor &ca,
const QColor &cb, GradientType type, int xfactor = 100,
int yfactor = 100, int ncols=3);
/**
* Creates a pixmap of a given size with the given pixmap.
*
* if the
* given size is bigger than the size of the pixmap, the pixmap is
* tiled.
*
* @param pixmap This is the source pixmap
* @param size The size the new pixmap should have.
* @return The generated, tiled pixmap.
*/
static OPixmap createTiled(const OPixmap& pixmap, QSize size);
/**
* Either brightens or dims a pixmap by a specified ratio.
*
* @param pixmap The pixmap to process.
* @param ratio The ratio to use. Use negative value to dim.
* @return Returns The @ref pixmap(), provided for convenience.
*/
static OPixmap& intensity(OPixmap& pixmap, float ratio);
/**
* Modifies the intensity of a pixmap's RGB channel component.
*
* @param pixmap The pixmap to process.
* @param ratio value. Use negative value to dim.
* @param channel Which channel(s) should be modified
* @return Returns the @ref pixmap(), provided for convenience.
*/
static OPixmap& channelIntensity(OPixmap& pixmap, float ratio,
RGBComponent channel);
/**
* Blends the provided pixmap into a background of the indicated color.
*
* @param pixmap The pixmap to process.
* @param initial_intensity this parameter takes values from -1 to 1:
* @li If positive, it tells how much to fade the image in its
* less affected spot.
* @li If negative, it tells roughly indicates how much of the image
* remains unaffected
* @param bgnd Indicates the color of the background to blend in.
* @param eff Lets you choose what kind of blending you like.
* @param anti_dir Blend in the opposite direction (makes no much sense
* with concentric blending effects).
* @return Returns the @ref pixmap(), provided for convenience.
*/
static OPixmap& blend(OPixmap& pixmap, float initial_intensity,
const QColor &bgnd, GradientType eff,
bool anti_dir=false, int ncols=3);
/**
* Builds a hash on any given pixmap.
*
* @param pixmap The pixmap to process.
* @param lite The hash faces the indicated lighting (cardinal poles)
* @param spacing How many unmodified pixels inbetween hashes.
* @return Returns The @ref pixmap(), provided for convenience.
*/
static OPixmap& hash(OPixmap& pixmap, Lighting lite=NorthLite,
unsigned int spacing=0, int ncols=3);
/**
* Creates a pattern from a pixmap.
*
* The given pixmap is "flattened"
* between color a to color b.
*
* @param pixmap The pixmap to process.
* @param ca Color a.
* @param cb Color b.
* @param ncols The number of colors to use. The image will be
* dithered to this depth. Pass zero to prevent dithering.
* @return The @ref pixmap(), provided for convenience.
*/
static OPixmap pattern(const OPixmap& pixmap, QSize size,
const QColor &ca, const QColor &cb, int ncols=8);
/**
* Recolors a pixmap.
*
* The most dark color will become color a,
* the most bright one color b, and in between.
*
* @param pixmap The pixmap to process.
* @param ca Color a.
* @param cb Color b.
* @param ncols The number of colors to use. Pass zero to prevent
* dithering.
* @return Returns the @ref pixmap(), provided for convenience.
*/
static OPixmap& fade(OPixmap& pixmap, double val, const QColor &color);
/**
* Converts a pixmap to grayscale.
*
* @param pixmap The pixmap to process.
* @param fast Set to @p true in order to use a faster but non-photographic
* quality algorithm. Appropriate for things such as toolbar icons.
* @return Returns the @ref pixmap(), provided for convenience.
*/
static OPixmap& toGray(OPixmap& pixmap, bool fast=false);
/**
* Desaturates a pixmap.
*
* @param pixmap The pixmap to process.
* @param desat A value between 0 and 1 setting the degree of desaturation
* @return Returns The @ref pixmap(), provided for convenience.
*/
static OPixmap& desaturate(OPixmap& pixmap, float desat = 0.3);
/**
* Modifies the contrast of a pixmap.
*
* @param pixmap The pixmap to process.
* @param c A contrast value between -255 and 255.
* @return Returns the @ref pixmap(), provided for convenience.
*/
static OPixmap& contrast(OPixmap& pixmap, int c);
/**
* Dithers a pixmap using Floyd-Steinberg dithering for low-color
* situations.
*
* @param pixmap The pixmap to process.
* @param palette The color palette to use.
* @param size The size of the palette.
* @return Returns the @ref pixmap(), provided for convenience.
*/
static OPixmap& dither(OPixmap &pixmap, const QColor *palette, int size);
/**
* Calculate a 'selected' pixmap, for instance a selected icon
* on the desktop.
* @param pixmap the pixmap to select
* @param col the selected color, usually from QColorGroup::highlight().
*/
static OPixmap selectedPixmap( const OPixmap &pixmap, const QColor &col );
};
-
+}
+}
#endif
diff --git a/libopie2/opieui/opixmapprovider.cpp b/libopie2/opieui/opixmapprovider.cpp
index 7be9e3b..7eb67a2 100644
--- a/libopie2/opieui/opixmapprovider.cpp
+++ b/libopie2/opieui/opixmapprovider.cpp
@@ -1,27 +1,29 @@
/* This file is part of the KDE libraries
Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License (LGPL) as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/opixmapprovider.h>
+using namespace Opie::Ui;
+
OPixmapProvider::~OPixmapProvider() {}
void OPixmapProvider::virtual_hook( int , void* )
{ /*BASE::virtual_hook( id, data );*/ }
diff --git a/libopie2/opieui/opixmapprovider.h b/libopie2/opieui/opixmapprovider.h
index 5b76647..9d9bd69 100644
--- a/libopie2/opieui/opixmapprovider.h
+++ b/libopie2/opieui/opixmapprovider.h
@@ -1,54 +1,62 @@
/* This file is part of the KDE libraries
Copyright (c) 2000 Carsten Pfeiffer <pfeiffer@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License (LGPL) as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OPIXMAPPROVIDER_H
#define OPIXMAPPROVIDER_H
#include <qpixmap.h>
+namespace Opie {
+namespace Ui {
/**
+ * \todo make usefull
* A tiny abstract class with just one method:
* @ref pixmapFor()
*
* It will be called whenever an icon is searched for @p text.
*
* Used e.g. by @ref KHistoryCombo
*
* @author Carsten Pfeiffer <pfeiffer@kde.org>
* @short an abstract interface for looking up icons
*/
class OPixmapProvider
{
public:
virtual ~OPixmapProvider();
/**
* You may subclass this and return a pixmap of size @p size for @p text.
* @param text the text that is associated with the pixmap
* @param size the size of the icon in pixels, 0 for defaylt size.
* See @ref KIcon::StdSize.
* @return the pixmap for the arguments, or null if there is none
*/
virtual QPixmap pixmapFor( const QString& text, int size = 0 ) = 0;
protected:
virtual void virtual_hook( int id, void* data );
+private:
+ class Private;
+ Private *d;
};
+}
+}
#endif // OPIXMAPPROVIDER_H
diff --git a/libopie2/opieui/opopupmenu.cpp b/libopie2/opieui/opopupmenu.cpp
index d5cc575..3ab8490 100644
--- a/libopie2/opieui/opopupmenu.cpp
+++ b/libopie2/opieui/opopupmenu.cpp
@@ -1,413 +1,416 @@
/* This file is part of the KDE libraries
Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
Copyright (C) 2002 Hamish Rodda <meddie@yoyo.its.monash.edu.au>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* QT */
#include <qdrawutil.h>
#include <qtimer.h>
/* OPIE */
#include <opie2/opopupmenu.h>
#include <opie2/oconfig.h>
+using namespace Opie::Core;
+using namespace Opie::Ui;
+
OPopupTitle::OPopupTitle(QWidget *parent, const char *name)
: QWidget(parent, name)
{
setMinimumSize(16, fontMetrics().height()+8);
}
OPopupTitle::OPopupTitle(OPixmapEffect::GradientType /* gradient */,
const QColor &/* color */, const QColor &/* textColor */,
QWidget *parent, const char *name)
: QWidget(parent, name)
{
setMinimumSize(16, fontMetrics().height()+8);
}
OPopupTitle::OPopupTitle(const OPixmap & /* background */, const QColor &/* color */,
const QColor &/* textColor */, QWidget *parent,
const char *name)
: QWidget(parent, name)
{
setMinimumSize(16, fontMetrics().height()+8);
}
void OPopupTitle::setTitle(const QString &text, const QPixmap *icon)
{
titleStr = text;
if (icon)
miniicon = *icon;
else
miniicon.resize(0, 0);
int w = miniicon.width()+fontMetrics().width(titleStr);
int h = QMAX( fontMetrics().height(), miniicon.height() );
setMinimumSize( w+16, h+8 );
}
void OPopupTitle::setText( const QString &text )
{
titleStr = text;
int w = miniicon.width()+fontMetrics().width(titleStr);
int h = QMAX( fontMetrics().height(), miniicon.height() );
setMinimumSize( w+16, h+8 );
}
void OPopupTitle::setIcon( const QPixmap &pix )
{
miniicon = pix;
int w = miniicon.width()+fontMetrics().width(titleStr);
int h = QMAX( fontMetrics().height(), miniicon.height() );
setMinimumSize( w+16, h+8 );
}
void OPopupTitle::paintEvent(QPaintEvent *)
{
QRect r(rect());
QPainter p(this);
#if QT_VERSION > 290
qApp->style().drawPrimitive(QStyle::PE_HeaderSection, &p, r, palette().active());
#else
#warning OPopupMenu is not fully functional on Qt2
#endif
if (!miniicon.isNull())
p.drawPixmap(4, (r.height()-miniicon.height())/2, miniicon);
if (!titleStr.isNull())
{
p.setPen(palette().active().text());
QFont f = p.font();
f.setBold(true);
p.setFont(f);
if(!miniicon.isNull())
{
p.drawText(miniicon.width()+8, 0, width()-(miniicon.width()+8),
height(), AlignLeft | AlignVCenter | SingleLine,
titleStr);
}
else
{
p.drawText(0, 0, width(), height(),
AlignCenter | SingleLine, titleStr);
}
}
p.setPen(palette().active().highlight());
p.drawLine(0, 0, r.right(), 0);
}
QSize OPopupTitle::sizeHint() const
{
return(minimumSize());
}
class OPopupMenu::OPopupMenuPrivate
{
public:
OPopupMenuPrivate ()
: noMatches(false)
, shortcuts(false)
, autoExec(false)
, lastHitIndex(-1)
, m_ctxMenu(0)
{}
~OPopupMenuPrivate ()
{
delete m_ctxMenu;
}
QString m_lastTitle;
// variables for keyboard navigation
QTimer clearTimer;
bool noMatches : 1;
bool shortcuts : 1;
bool autoExec : 1;
QString keySeq;
QString originalText;
int lastHitIndex;
// support for RMB menus on menus
QPopupMenu* m_ctxMenu;
static bool s_continueCtxMenuShow;
static int s_highlightedItem;
static OPopupMenu* s_contextedMenu;
};
int OPopupMenu::OPopupMenuPrivate::s_highlightedItem(-1);
OPopupMenu* OPopupMenu::OPopupMenuPrivate::s_contextedMenu(0);
bool OPopupMenu::OPopupMenuPrivate::s_continueCtxMenuShow(true);
OPopupMenu::OPopupMenu(QWidget *parent, const char *name)
: QPopupMenu(parent, name)
{
d = new OPopupMenuPrivate;
resetKeyboardVars();
connect(&(d->clearTimer), SIGNAL(timeout()), SLOT(resetKeyboardVars()));
}
OPopupMenu::~OPopupMenu()
{
if (OPopupMenuPrivate::s_contextedMenu == this)
{
OPopupMenuPrivate::s_contextedMenu = 0;
OPopupMenuPrivate::s_highlightedItem = -1;
}
delete d;
}
int OPopupMenu::insertTitle(const QString &text, int id, int index)
{
OPopupTitle *titleItem = new OPopupTitle();
titleItem->setTitle(text);
int ret = insertItem(titleItem, id, index);
setItemEnabled(id, false);
return ret;
}
int OPopupMenu::insertTitle(const QPixmap &icon, const QString &text, int id,
int index)
{
OPopupTitle *titleItem = new OPopupTitle();
titleItem->setTitle(text, &icon);
int ret = insertItem(titleItem, id, index);
setItemEnabled(id, false);
return ret;
}
void OPopupMenu::changeTitle(int id, const QString &text)
{
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
((OPopupTitle *)item->widget())->setTitle(text);
#ifndef NDEBUG
else
qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id );
#endif
}
#ifndef NDEBUG
else
qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id );
#endif
}
void OPopupMenu::changeTitle(int id, const QPixmap &icon, const QString &text)
{
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
((OPopupTitle *)item->widget())->setTitle(text, &icon);
#ifndef NDEBUG
else
qWarning( "KPopupMenu: changeTitle() called with non-title id %d", id );
#endif
}
#ifndef NDEBUG
else
qWarning( "KPopupMenu: changeTitle() called with invalid id %d", id );
#endif
}
QString OPopupMenu::title(int id) const
{
if(id == -1) // obsolete
return(d->m_lastTitle);
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
return(((OPopupTitle *)item->widget())->title());
else
qWarning("OPopupMenu: title() called with non-title id %d.", id);
}
else
qWarning("OPopupMenu: title() called with invalid id %d.", id);
return(QString::null);
}
QPixmap OPopupMenu::titlePixmap(int id) const
{
QMenuItem *item = findItem(id);
if(item){
if(item->widget())
return(((OPopupTitle *)item->widget())->icon());
else
qWarning("KPopupMenu: titlePixmap() called with non-title id %d.", id);
}
else
qWarning("KPopupMenu: titlePixmap() called with invalid id %d.", id);
QPixmap tmp;
return(tmp);
}
/**
* This is re-implemented for keyboard navigation.
*/
void OPopupMenu::closeEvent(QCloseEvent*e)
{
if (d->shortcuts)
resetKeyboardVars();
QPopupMenu::closeEvent(e);
}
void OPopupMenu::keyPressEvent(QKeyEvent* e)
{
if (!d->shortcuts) {
// continue event processing by Qpopup
//e->ignore();
QPopupMenu::keyPressEvent(e);
return;
}
int i = 0;
bool firstpass = true;
QString keyString = e->text();
// check for common commands dealt with by QPopup
int key = e->key();
if (key == Key_Escape || key == Key_Return || key == Key_Enter
|| key == Key_Up || key == Key_Down || key == Key_Left
|| key == Key_Right || key == Key_F1) {
resetKeyboardVars();
// continue event processing by Qpopup
//e->ignore();
QPopupMenu::keyPressEvent(e);
return;
}
// check to see if the user wants to remove a key from the sequence (backspace)
// or clear the sequence (delete)
if (!d->keySeq.isNull()) {
if (key == Key_Backspace) {
if (d->keySeq.length() == 1) {
resetKeyboardVars();
return;
}
// keep the last sequence in keyString
keyString = d->keySeq.left(d->keySeq.length() - 1);
// allow sequence matching to be tried again
resetKeyboardVars();
} else if (key == Key_Delete) {
resetKeyboardVars();
// clear active item
setActiveItem(0);
return;
} else if (d->noMatches) {
// clear if there are no matches
resetKeyboardVars();
// clear active item
setActiveItem(0);
} else {
// the key sequence is not a null string
// therefore the lastHitIndex is valid
i = d->lastHitIndex;
}
} else if (key == Key_Backspace && parentMenu) {
// backspace with no chars in the buffer... go back a menu.
hide();
resetKeyboardVars();
return;
}
d->keySeq += keyString;
int seqLen = d->keySeq.length();
for (; i < (int)count(); i++) {
// compare typed text with text of this entry
int j = idAt(i);
// don't search disabled entries
if (!isItemEnabled(j))
continue;
QString thisText;
// retrieve the right text
// (the last selected item one may have additional ampersands)
if (i == d->lastHitIndex)
thisText = d->originalText;
else
thisText = text(j);
// if there is an accelerator present, remove it
if ((int)accel(j) != 0)
thisText = thisText.replace(QRegExp("&"), "");
// chop text to the search length
thisText = thisText.left(seqLen);
// do the search
if (thisText.find(d->keySeq, 0, false) == 0) {
if (firstpass) {
// match
setActiveItem(i);
// check to see if we're underlining a different item
if (d->lastHitIndex != i)
// yes; revert the underlining
changeItem(idAt(d->lastHitIndex), d->originalText);
// set the original text if it's a different item
if (d->lastHitIndex != i || d->lastHitIndex == -1)
d->originalText = text(j);
// underline the currently selected item
changeItem(j, underlineText(d->originalText, d->keySeq.length()));
// remeber what's going on
d->lastHitIndex = i;
// start/restart the clear timer
d->clearTimer.start(5000, true);
// go around for another try, to see if we can execute
firstpass = false;
} else {
// don't allow execution
return;
}
}
// fall through to allow execution
}
if (!firstpass) {
if (d->autoExec) {
// activate anything
activateItemAt(d->lastHitIndex);
resetKeyboardVars();
diff --git a/libopie2/opieui/opopupmenu.h b/libopie2/opieui/opopupmenu.h
index 54e4301..419a954 100644
--- a/libopie2/opieui/opopupmenu.h
+++ b/libopie2/opieui/opopupmenu.h
@@ -1,259 +1,264 @@
//FIXME what is ODE? ODE Desktop Environemt? -zecke
//FIXME do we need titles? space is limited that is only eyecandy? -zecke
//FIXME keyboard navigation is also not that popular on a PDA might be with a keyboard (tuxphone) -zecke
/* This file is part of the ODE libraries
Copyright (C) 2000 Daniel M. Duley <mosfet@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef _OPOPUP_H
#define _OPOPUP_H
#define INCLUDE_MENUITEM_DEF
/* QT */
#include <qpopupmenu.h>
/* OPIE */
#include <opie2/opixmapeffect.h>
+namespace Opie {
+namespace Ui {
/**
* Title widget for use in @ref OPopupMenu.
*
* You usually don't have to create this manually since
* @ref OPopupMenu::insertTitle will do it for you, but it is allowed if
* you wish to customize it's look.
*
* @author Daniel M. Duley <mosfet@kde.org>
* @short OPopupMenu title widget.
*/
class OPopupTitle : public QWidget
{
Q_OBJECT
public:
/**
* Constructs a title widget with the user specified gradient, pixmap,
* and colors.
*/
OPopupTitle(QWidget *parent=0, const char *name=0);
/**
* @deprecated
* Constructs a title widget with the specified gradient and colors.
*/
OPopupTitle(OPixmapEffect::GradientType gradient, const QColor &color,
const QColor &textColor, QWidget *parent=0,
const char *name=0);
/**
* @deprecated
* Constructs a title widget with the specified pixmap and colors.
*/
OPopupTitle(const OPixmap &background, const QColor &color,
const QColor &textColor, QWidget *parent=0,
const char *name=0);
/**
* Sets the title string and optional icon for the title widget.
*
* You will want to call this before inserting into a menu.
*/
void setTitle(const QString &text, const QPixmap *icon=NULL);
/**
* Returns the current title.
*/
QString title() const { return(titleStr); }
/**
* Returns the current icon.
*/
QPixmap icon() const { return(miniicon); }
QSize sizeHint() const;
public slots:
/// @since 3.1
void setText( const QString &text );
/// @since 3.1
void setIcon( const QPixmap &pix );
protected:
void paintEvent(QPaintEvent *ev);
QString titleStr;
QPixmap miniicon;
// Remove in KDE4
OPixmapEffect::GradientType grType;
QPixmap fill;
QColor fgColor, bgColor, grHigh, grLow;
bool useGradient;
protected:
virtual void virtual_hook( int id, void* data );
private:
class OPopupTitlePrivate;
OPopupTitlePrivate *d;
};
/**
* OPopupMenu is a class for menus with standard title items and keyboard
* accessibility for popups with many options and/or varying options. It acts
* identically to QPopupMenu, with the addition of insertTitle(),
* changeTitle(), setKeyboardShortcutsEnabled() and
* setKeyboardShortcutsExecute() methods.
*
* The titles support a text string, an icon, plus user defined gradients,
* colors, and background pixmaps.
*
* The keyboard search algorithm is incremental with additional underlining
* for user feedback.
*
* @short A menu with title items.
* @author Daniel M. Duley <mosfet@kde.org>
* @author Hamish Rodda <meddie@yoyo.its.monash.edu.au>
*/
class OPopupMenu : public QPopupMenu {
Q_OBJECT
public:
/**
* Constructs a OPopupMenu.
*/
OPopupMenu(QWidget *parent=0, const char *name=0);
/**
* Destructs the object
*/
~OPopupMenu();
/**
* Inserts a title item with no icon.
*/
int insertTitle(const QString &text, int id=-1, int index=-1);
/**
* Inserts a title item with the given icon and title.
*/
int insertTitle(const QPixmap &icon, const QString &text, int id=-1,
int index=-1);
/**
* Changes the title of the item at the specified id. If a icon was
* previously set it is cleared.
*/
void changeTitle(int id, const QString &text);
/**
* Changes the title and icon of the title item at the specified id.
*/
void changeTitle(int id, const QPixmap &icon, const QString &text);
/**
* Returns the title of the title item at the specified id. The default
* id of -1 is for backwards compatibility only, you should always specify
* the id.
*/
QString title(int id=-1) const;
/**
* Returns the icon of the title item at the specified id.
*/
QPixmap titlePixmap(int id) const;
/**
* Enables keyboard navigation by searching for the entered key sequence.
* Also underlines the currently selected item, providing feedback on the search.
*
* Defaults to off.
*
* WARNING: calls to text() of currently keyboard-selected items will
* contain additional ampersand characters.
*
* WARNING: though pre-existing keyboard shortcuts will not interfere with the
* operation of this feature, they may be confusing to the user as the existing
* shortcuts will not work.
* @since 3.1
*/
void setKeyboardShortcutsEnabled(bool enable);
/**
* Enables execution of the menu item once it is uniquely specified.
* Defaults to off.
* @since 3.1
*/
void setKeyboardShortcutsExecute(bool enable);
/**
* Obsolete method provided for backwards compatibility only. Use the
* normal constructor and insertTitle instead.
*/
OPopupMenu(const QString &title, QWidget *parent=0, const char *name=0);
/**
* Obsolete method provided for backwards compatibility only. Use
* insertTitle and changeTitle instead.
*/
void setTitle(const QString &title);
/**
* Returns the context menu associated with this menu
* @since 3.2
*/
QPopupMenu* contextMenu();
/**
* Hides the context menu if shown
* @since 3.2
*/
void cancelContextMenuShow();
/**
* Returns the OPopupMenu associated with the current context menu
* @since 3.2
*/
static OPopupMenu* contextMenuFocus();
/**
* returns the ID of the menuitem associated with the current context menu
* @since 3.2
*/
static int contextMenuFocusItem();
signals:
/**
* connect to this signal to be notified when a context menu is about to be shown
* @param menu The menu that the context menu is about to be shown for
* @param menuItem The menu item that the context menu is currently on
* @param ctxMenu The context menu itself
* @since 3.2
*/
void aboutToShowContextMenu(OPopupMenu* menu, int menuItem, QPopupMenu* ctxMenu);
protected:
virtual void closeEvent(QCloseEvent *);
virtual void keyPressEvent(QKeyEvent* e);
virtual bool eventFilter(QObject* obj, QEvent* event);
virtual void hideEvent(QHideEvent*);
virtual void virtual_hook( int id, void* data );
protected slots:
/// @since 3.1
QString underlineText(const QString& text, uint length);
/// @since 3.1
void resetKeyboardVars(bool noMatches = false);
void itemHighlighted(int whichItem);
void showCtxMenu(QPoint pos);
void ctxMenuHiding();
private:
class OPopupMenuPrivate;
OPopupMenuPrivate *d;
};
+}
+}
+
#endif
diff --git a/libopie2/opieui/oselector.cpp b/libopie2/opieui/oselector.cpp
index 23b3ce3..5f6f10f 100644
--- a/libopie2/opieui/oselector.cpp
+++ b/libopie2/opieui/oselector.cpp
@@ -1,715 +1,717 @@
/* This file is part of the KDE libraries
Copyright (C) 1997 Martin Jones (mjones@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* QT */
#include <qimage.h>
#include <qdrawutil.h>
/* OPIE */
#include <opie2/oimageeffect.h>
#include <opie2/oselector.h>
#define STORE_W 8
#define STORE_W2 STORE_W * 2
//-----------------------------------------------------------------------------
/*
* 2D value selector.
* The contents of the selector are drawn by derived class.
*/
+using namespace Opie::Ui;
+
OXYSelector::OXYSelector( QWidget *parent, const char *name )
: QWidget( parent, name )
{
xPos = 0;
yPos = 0;
minX = 0;
minY = 0;
maxX = 100;
maxY = 100;
store.setOptimization( QPixmap::BestOptim );
store.resize( STORE_W2, STORE_W2 );
}
OXYSelector::~OXYSelector()
{}
void OXYSelector::setRange( int _minX, int _minY, int _maxX, int _maxY )
{
px = 2;
py = 2;
minX = _minX;
minY = _minY;
maxX = _maxX;
maxY = _maxY;
}
void OXYSelector::setValues( int _xPos, int _yPos )
{
xPos = _xPos;
yPos = _yPos;
if ( xPos > maxX )
xPos = maxX;
else if ( xPos < minX )
xPos = minX;
-
+
if ( yPos > maxY )
yPos = maxY;
else if ( yPos < minY )
yPos = minY;
int xp = 2 + (width() - 4) * xPos / (maxX - minX);
int yp = height() - 2 - (height() - 4) * yPos / (maxY - minY);
setPosition( xp, yp );
}
QRect OXYSelector::contentsRect() const
{
return QRect( 2, 2, width()-4, height()-4 );
}
void OXYSelector::paintEvent( QPaintEvent *ev )
{
QRect cursorRect( px - STORE_W, py - STORE_W, STORE_W2, STORE_W2);
QRect paintRect = ev->rect();
QPainter painter;
painter.begin( this );
QBrush brush;
qDrawShadePanel( &painter, 0, 0, width(), height(), colorGroup(),
TRUE, 2, &brush );
drawContents( &painter );
if (paintRect.contains(cursorRect))
{
bitBlt( &store, 0, 0, this, px - STORE_W, py - STORE_W,
STORE_W2, STORE_W2, CopyROP );
drawCursor( &painter, px, py );
}
else if (paintRect.intersects(cursorRect))
{
repaint( cursorRect, false);
}
painter.end();
}
void OXYSelector::mousePressEvent( QMouseEvent *e )
{
int xVal, yVal;
valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
setValues( xVal, yVal );
emit valueChanged( xPos, yPos );
}
void OXYSelector::mouseMoveEvent( QMouseEvent *e )
{
int xVal, yVal;
valuesFromPosition( e->pos().x() - 2, e->pos().y() - 2, xVal, yVal );
setValues( xVal, yVal );
emit valueChanged( xPos, yPos );
}
void OXYSelector::wheelEvent( QWheelEvent *e )
{
#if QT_VERSION > 290
if ( e->orientation() == Qt::Horizontal )
setValues( xValue() + e->delta()/120, yValue() );
else
setValues( xValue(), yValue() + e->delta()/120 );
emit valueChanged( xPos, yPos );
#endif
}
void OXYSelector::valuesFromPosition( int x, int y, int &xVal, int &yVal ) const
{
xVal = ( (maxX-minX) * (x-2) ) / ( width()-4 );
yVal = maxY - ( ( (maxY-minY) * (y-2) ) / ( height()-4 ) );
if ( xVal > maxX )
xVal = maxX;
else if ( xVal < minX )
xVal = minX;
if ( yVal > maxY )
yVal = maxY;
else if ( yVal < minY )
yVal = minY;
}
void OXYSelector::setPosition( int xp, int yp )
{
if ( xp < 2 )
xp = 2;
else if ( xp > width() - 2 )
xp = width() - 2;
if ( yp < 2 )
yp = 2;
else if ( yp > height() - 2 )
yp = height() - 2;
QPainter painter;
painter.begin( this );
bitBlt( this, px - STORE_W, py - STORE_W, &store, 0, 0,
STORE_W2, STORE_W2, CopyROP );
bitBlt( &store, 0, 0, this, xp - STORE_W, yp - STORE_W,
STORE_W2, STORE_W2, CopyROP );
drawCursor( &painter, xp, yp );
px = xp;
py = yp;
painter.end();
}
void OXYSelector::drawContents( QPainter * )
{}
void OXYSelector::drawCursor( QPainter *p, int xp, int yp )
{
p->setPen( QPen( white ) );
p->drawLine( xp - 6, yp - 6, xp - 2, yp - 2 );
p->drawLine( xp - 6, yp + 6, xp - 2, yp + 2 );
p->drawLine( xp + 6, yp - 6, xp + 2, yp - 2 );
p->drawLine( xp + 6, yp + 6, xp + 2, yp + 2 );
}
//-----------------------------------------------------------------------------
/*
* 1D value selector with contents drawn by derived class.
* See OColorDialog for example.
*/
OSelector::OSelector( QWidget *parent, const char *name )
: QWidget( parent, name ), QRangeControl()
{
_orientation = Horizontal;
_indent = TRUE;
}
OSelector::OSelector( Orientation o, QWidget *parent, const char *name )
: QWidget( parent, name ), QRangeControl()
{
_orientation = o;
_indent = TRUE;
}
OSelector::~OSelector()
{}
QRect OSelector::contentsRect() const
{
if ( orientation() == Vertical )
return QRect( 2, 5, width()-9, height()-10 );
else
return QRect( 5, 2, width()-10, height()-9 );
}
void OSelector::paintEvent( QPaintEvent * )
{
QPainter painter;
painter.begin( this );
drawContents( &painter );
QBrush brush;
if ( indent() )
{
if ( orientation() == Vertical )
qDrawShadePanel( &painter, 0, 3, width()-5, height()-6,
colorGroup(), TRUE, 2, &brush );
else
qDrawShadePanel( &painter, 3, 0, width()-6, height()-5,
colorGroup(), TRUE, 2, &brush );
}
QPoint pos = calcArrowPos( value() );
- drawArrow( &painter, TRUE, pos );
+ drawArrow( &painter, TRUE, pos );
painter.end();
}
void OSelector::mousePressEvent( QMouseEvent *e )
{
moveArrow( e->pos() );
}
void OSelector::mouseMoveEvent( QMouseEvent *e )
{
moveArrow( e->pos() );
}
void OSelector::wheelEvent( QWheelEvent *e )
{
int val = value() + e->delta()/120;
emit valueChanged( val );
setValue( val );
}
void OSelector::valueChange()
{
QPainter painter;
QPoint pos;
painter.begin( this );
pos = calcArrowPos( prevValue() );
- drawArrow( &painter, FALSE, pos );
+ drawArrow( &painter, FALSE, pos );
pos = calcArrowPos( value() );
- drawArrow( &painter, TRUE, pos );
+ drawArrow( &painter, TRUE, pos );
painter.end();
}
void OSelector::moveArrow( const QPoint &pos )
{
int val;
if ( orientation() == Vertical )
val = ( maxValue() - minValue() ) * (height()-pos.y()-3)
/ (height()-10) + minValue();
else
val = ( maxValue() - minValue() ) * (width()-pos.x()-3)
/ (width()-10) + minValue();
if ( val > maxValue() )
val = maxValue();
if ( val < minValue() )
val = minValue();
emit valueChanged( val );
setValue( val );
}
QPoint OSelector::calcArrowPos( int val )
{
QPoint p;
if ( orientation() == Vertical )
{
p.setY( height() - ( (height()-10) * val
/ ( maxValue() - minValue() ) + 5 ) );
p.setX( width() - 5 );
}
else
{
p.setX( width() - ( (width()-10) * val
/ ( maxValue() - minValue() ) + 5 ) );
p.setY( height() - 5 );
}
return p;
}
void OSelector::drawContents( QPainter * )
{}
void OSelector::drawArrow( QPainter *painter, bool show, const QPoint &pos )
{
if ( show )
{
QPointArray array(3);
painter->setPen( QPen() );
painter->setBrush( QBrush( colorGroup().buttonText() ) );
if ( orientation() == Vertical )
{
array.setPoint( 0, pos.x()+0, pos.y()+0 );
array.setPoint( 1, pos.x()+5, pos.y()+5 );
array.setPoint( 2, pos.x()+5, pos.y()-5 );
}
else
{
array.setPoint( 0, pos.x()+0, pos.y()+0 );
array.setPoint( 1, pos.x()+5, pos.y()+5 );
array.setPoint( 2, pos.x()-5, pos.y()+5 );
}
painter->drawPolygon( array );
- }
- else
+ }
+ else
{
if ( orientation() == Vertical )
{
repaint(pos.x(), pos.y()-5, 6, 11, true);
}
else
{
repaint(pos.x()-5, pos.y(), 11, 6, true);
}
}
}
//----------------------------------------------------------------------------
OGradientSelector::OGradientSelector( QWidget *parent, const char *name )
: OSelector( parent, name )
{
init();
}
OGradientSelector::OGradientSelector( Orientation o, QWidget *parent,
const char *name )
: OSelector( o, parent, name )
{
init();
}
OGradientSelector::~OGradientSelector()
{}
void OGradientSelector::init()
{
color1.setRgb( 0, 0, 0 );
color2.setRgb( 255, 255, 255 );
-
+
text1 = text2 = "";
}
void OGradientSelector::drawContents( QPainter *painter )
{
QImage image( contentsRect().width(), contentsRect().height(), 32 );
QColor col;
float scale;
int redDiff = color2.red() - color1.red();
int greenDiff = color2.green() - color1.green();
int blueDiff = color2.blue() - color1.blue();
if ( orientation() == Vertical )
{
for ( int y = 0; y < image.height(); y++ )
{
scale = 1.0 * y / image.height();
col.setRgb( color1.red() + int(redDiff*scale),
color1.green() + int(greenDiff*scale),
color1.blue() + int(blueDiff*scale) );
unsigned int *p = (uint *) image.scanLine( y );
for ( int x = 0; x < image.width(); x++ )
*p++ = col.rgb();
}
}
else
{
unsigned int *p = (uint *) image.scanLine( 0 );
for ( int x = 0; x < image.width(); x++ )
{
scale = 1.0 * x / image.width();
col.setRgb( color1.red() + int(redDiff*scale),
color1.green() + int(greenDiff*scale),
color1.blue() + int(blueDiff*scale) );
*p++ = col.rgb();
}
for ( int y = 1; y < image.height(); y++ )
memcpy( image.scanLine( y ), image.scanLine( y - 1),
sizeof( unsigned int ) * image.width() );
}
QColor ditherPalette[8];
for ( int s = 0; s < 8; s++ )
ditherPalette[s].setRgb( color1.red() + redDiff * s / 8,
color1.green() + greenDiff * s / 8,
color1.blue() + blueDiff * s / 8 );
OImageEffect::dither( image, ditherPalette, 8 );
QPixmap p;
p.convertFromImage( image );
painter->drawPixmap( contentsRect().x(), contentsRect().y(), p );
if ( orientation() == Vertical )
{
int yPos = contentsRect().top() + painter->fontMetrics().ascent() + 2;
int xPos = contentsRect().left() + (contentsRect().width() -
painter->fontMetrics().width( text2 )) / 2;
QPen pen( color2 );
painter->setPen( pen );
painter->drawText( xPos, yPos, text2 );
yPos = contentsRect().bottom() - painter->fontMetrics().descent() - 2;
- xPos = contentsRect().left() + (contentsRect().width() -
+ xPos = contentsRect().left() + (contentsRect().width() -
painter->fontMetrics().width( text1 )) / 2;
pen.setColor( color1 );
painter->setPen( pen );
painter->drawText( xPos, yPos, text1 );
}
else
{
int yPos = contentsRect().bottom()-painter->fontMetrics().descent()-2;
QPen pen( color2 );
painter->setPen( pen );
painter->drawText( contentsRect().left() + 2, yPos, text1 );
pen.setColor( color1 );
painter->setPen( pen );
painter->drawText( contentsRect().right() -
painter->fontMetrics().width( text2 ) - 2, yPos, text2 );
}
}
//-----------------------------------------------------------------------------
static QColor *standardPalette = 0;
#define STANDARD_PAL_SIZE 17
OColor::OColor()
: QColor()
{
r = 0; g = 0; b = 0; h = 0; s = 0; v = 0;
};
OColor::OColor( const OColor &col)
: QColor( col )
{
h = col.h; s = col.s; v = col.v;
r = col.r; g = col.g; b = col.b;
};
OColor::OColor( const QColor &col)
: QColor( col )
{
QColor::rgb(&r, &g, &b);
QColor::hsv(&h, &s, &v);
};
bool OColor::operator==(const OColor& col) const
{
return (h == col.h) && (s == col.s) && (v == col.v) &&
(r == col.r) && (g == col.g) && (b == col.b);
}
OColor& OColor::operator=(const OColor& col)
{
*(QColor *)this = col;
h = col.h; s = col.s; v = col.v;
r = col.r; g = col.g; b = col.b;
return *this;
}
void
OColor::setHsv(int _h, int _s, int _v)
{
h = _h; s = _s; v = _v;
QColor::setHsv(h, s, v);
QColor::rgb(&r, &g, &b);
};
void
OColor::setRgb(int _r, int _g, int _b)
{
r = _r; g = _g; b = _b;
QColor::setRgb(r, g, b);
QColor::hsv(&h, &s, &v);
}
void
OColor::rgb(int *_r, int *_g, int *_b) const
{
*_r = r; *_g = g; *_b = b;
}
void
OColor::hsv(int *_h, int *_s, int *_v) const
{
*_h = h; *_s = s; *_v = v;
}
static void createStandardPalette()
{
if ( standardPalette )
return;
standardPalette = new QColor[STANDARD_PAL_SIZE];
int i = 0;
standardPalette[i++] = Qt::red;
standardPalette[i++] = Qt::green;
standardPalette[i++] = Qt::blue;
standardPalette[i++] = Qt::cyan;
standardPalette[i++] = Qt::magenta;
standardPalette[i++] = Qt::yellow;
standardPalette[i++] = Qt::darkRed;
standardPalette[i++] = Qt::darkGreen;
standardPalette[i++] = Qt::darkBlue;
standardPalette[i++] = Qt::darkCyan;
standardPalette[i++] = Qt::darkMagenta;
standardPalette[i++] = Qt::darkYellow;
standardPalette[i++] = Qt::white;
standardPalette[i++] = Qt::lightGray;
standardPalette[i++] = Qt::gray;
standardPalette[i++] = Qt::darkGray;
standardPalette[i++] = Qt::black;
}
OHSSelector::OHSSelector( QWidget *parent, const char *name )
: OXYSelector( parent, name )
{
setRange( 0, 0, 359, 255 );
}
void OHSSelector::updateContents()
{
drawPalette(&pixmap);
}
void OHSSelector::resizeEvent( QResizeEvent * )
{
updateContents();
}
void OHSSelector::drawContents( QPainter *painter )
{
painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
}
void OHSSelector::drawPalette( QPixmap *pixmap )
{
int xSize = contentsRect().width(), ySize = contentsRect().height();
QImage image( xSize, ySize, 32 );
QColor col;
int h, s;
uint *p;
for ( s = ySize-1; s >= 0; s-- )
{
p = (uint *) image.scanLine( ySize - s - 1 );
for( h = 0; h < xSize; h++ )
{
col.setHsv( 359*h/(xSize-1), 255*s/(ySize-1), 192 );
*p = col.rgb();
p++;
}
}
if ( QColor::numBitPlanes() <= 8 )
{
createStandardPalette();
OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
}
pixmap->convertFromImage( image );
}
//-----------------------------------------------------------------------------
OValueSelector::OValueSelector( QWidget *parent, const char *name )
: OSelector( OSelector::Vertical, parent, name ), _hue(0), _sat(0)
{
setRange( 0, 255 );
pixmap.setOptimization( QPixmap::BestOptim );
}
OValueSelector::OValueSelector(Orientation o, QWidget *parent, const char *name
)
: OSelector( o, parent, name), _hue(0), _sat(0)
{
setRange( 0, 255 );
pixmap.setOptimization( QPixmap::BestOptim );
}
void OValueSelector::updateContents()
{
drawPalette(&pixmap);
}
void OValueSelector::resizeEvent( QResizeEvent * )
{
updateContents();
}
void OValueSelector::drawContents( QPainter *painter )
{
painter->drawPixmap( contentsRect().x(), contentsRect().y(), pixmap );
}
void OValueSelector::drawPalette( QPixmap *pixmap )
{
int xSize = contentsRect().width(), ySize = contentsRect().height();
QImage image( xSize, ySize, 32 );
QColor col;
uint *p;
QRgb rgb;
if ( orientation() == OSelector::Horizontal )
{
for ( int v = 0; v < ySize; v++ )
{
p = (uint *) image.scanLine( ySize - v - 1 );
for( int x = 0; x < xSize; x++ )
{
col.setHsv( _hue, _sat, 255*x/(xSize-1) );
rgb = col.rgb();
*p++ = rgb;
}
}
}
if( orientation() == OSelector::Vertical )
{
for ( int v = 0; v < ySize; v++ )
{
p = (uint *) image.scanLine( ySize - v - 1 );
col.setHsv( _hue, _sat, 255*v/(ySize-1) );
rgb = col.rgb();
for ( int i = 0; i < xSize; i++ )
*p++ = rgb;
}
}
if ( QColor::numBitPlanes() <= 8 )
{
createStandardPalette();
OImageEffect::dither( image, standardPalette, STANDARD_PAL_SIZE );
}
pixmap->convertFromImage( image );
}
diff --git a/libopie2/opieui/oselector.h b/libopie2/opieui/oselector.h
index f832239..fe75a46 100644
--- a/libopie2/opieui/oselector.h
+++ b/libopie2/opieui/oselector.h
@@ -1,518 +1,523 @@
/* This file is part of the KDE libraries
Copyright (C) 1997 Martin Jones (mjones@kde.org)
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
//-----------------------------------------------------------------------------
// Selector widgets for KDE Color Selector, but probably useful for other
// stuff also.
#ifndef __OSELECT_H__
#define __OSELECT_H__
#include <qwidget.h>
#include <qrangecontrol.h>
#include <qpixmap.h>
+
+namespace Opie {
+namespace Ui {
/**
* OXYSelector is the base class for other widgets which
* provides the ability to choose from a two-dimensional
* range of values. The currently chosen value is indicated
* by a cross. An example is the @ref OHSSelector which
* allows to choose from a range of colors, and which is
* used in OColorDialog.
*
* A custom drawing routine for the widget surface has
* to be provided by the subclass.
*/
class OXYSelector : public QWidget
{
Q_OBJECT
public:
/**
* Constructs a two-dimensional selector widget which
* has a value range of [0..100] in both directions.
*/
OXYSelector( QWidget *parent=0, const char *name=0 );
/**
* Destructs the widget.
*/
~OXYSelector();
/**
* Sets the current values in horizontal and
* vertical direction.
*/
void setValues( int xPos, int yPos );
/**
* Sets the range of possible values.
*/
void setRange( int minX, int minY, int maxX, int maxY );
/**
* @return the current value in horizontal direction.
*/
int xValue() const { return xPos; }
/**
* @return the current value in vertical direction.
*/
int yValue() const { return yPos; }
/**
* @return the rectangle on which subclasses should draw.
*/
QRect contentsRect() const;
signals:
/**
* This signal is emitted whenever the user chooses a value,
* e.g. by clicking with the mouse on the widget.
*/
void valueChanged( int x, int y );
protected:
/**
* Override this function to draw the contents of the widget.
* The default implementation does nothing.
*
* Draw within @ref contentsRect() only.
*/
virtual void drawContents( QPainter * );
/**
* Override this function to draw the cursor which
* indicates the currently selected value pair.
*/
virtual void drawCursor( QPainter *p, int xp, int yp );
/**
* @reimplemented
*/
virtual void paintEvent( QPaintEvent *e );
/**
* @reimplemented
*/
virtual void mousePressEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void mouseMoveEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void wheelEvent( QWheelEvent * );
/**
* Converts a pixel position to its corresponding values.
*/
void valuesFromPosition( int x, int y, int& xVal, int& yVal ) const;
private:
void setPosition( int xp, int yp );
int px;
int py;
int xPos;
int yPos;
int minX;
int maxX;
int minY;
int maxY;
QPixmap store;
private:
class OXYSelectorPrivate;
OXYSelectorPrivate *d;
};
/**
* OSelector is the base class for other widgets which
* provides the ability to choose from a one-dimensional
* range of values. An example is the @ref OGradientSelector
* which allows to choose from a range of colors.
*
* A custom drawing routine for the widget surface has
* to be provided by the subclass.
*/
class OSelector : public QWidget, public QRangeControl
{
Q_OBJECT
Q_PROPERTY( int value READ value WRITE setValue )
Q_PROPERTY( int minValue READ minValue WRITE setMinValue )
Q_PROPERTY( int maxValue READ maxValue WRITE setMaxValue )
public:
/**
* Constructs a horizontal one-dimensional selection widget.
*/
OSelector( QWidget *parent=0, const char *name=0 );
/**
* Constructs a one-dimensional selection widget with
* a given orientation.
*/
OSelector( Orientation o, QWidget *parent = 0L, const char *name = 0L );
/*
* Destructs the widget.
*/
~OSelector();
/**
* @return the orientation of the widget.
*/
Orientation orientation() const
{ return _orientation; }
/**
* @return the rectangle on which subclasses should draw.
*/
QRect contentsRect() const;
/**
* Sets the indent option of the widget to i.
* This determines whether a shaded frame is drawn.
*/
void setIndent( bool i )
{ _indent = i; }
/**
* @return whether the indent option is set.
*/
bool indent() const
{ return _indent; }
/**
* Sets the value.
*/
void setValue(int value)
{ QRangeControl::setValue(value); }
/**
* @returns the value.
*/
int value() const
{ return QRangeControl::value(); }
/**
* Sets the min value.
*/
#if ( QT_VERSION > 290 )
void setMinValue(int value) { QRangeControl::setMinValue(value); }
#else
void setMinValue(int value) { QRangeControl::setRange(value,QRangeControl::maxValue()); }
#endif
/**
* @return the min value.
*/
int minValue() const
{ return QRangeControl::minValue(); }
/**
* Sets the max value.
*/
#if ( QT_VERSION > 290 )
void setMaxValue(int value) { QRangeControl::setMaxValue(value); }
#else
void setMaxValue(int value) { QRangeControl::setRange(QRangeControl::minValue(),value); }
#endif
/**
* @return the max value.
*/
int maxValue() const
{ return QRangeControl::maxValue(); }
signals:
/**
* This signal is emitted whenever the user chooses a value,
* e.g. by clicking with the mouse on the widget.
*/
void valueChanged( int value );
protected:
/**
* Override this function to draw the contents of the control.
* The default implementation does nothing.
*
* Draw only within contentsRect().
*/
virtual void drawContents( QPainter * );
/**
* Override this function to draw the cursor which
* indicates the current value. This function is
* always called twice, once with argument show=false
* to clear the old cursor, once with argument show=true
* to draw the new one.
*/
virtual void drawArrow( QPainter *painter, bool show, const QPoint &pos );
/**
* @reimplemented
*/
virtual void valueChange();
/**
* @reimplemented
*/
virtual void paintEvent( QPaintEvent * );
/**
* @reimplemented
*/
virtual void mousePressEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void mouseMoveEvent( QMouseEvent *e );
/**
* @reimplemented
*/
virtual void wheelEvent( QWheelEvent * );
private:
QPoint calcArrowPos( int val );
void moveArrow( const QPoint &pos );
Orientation _orientation;
bool _indent;
private:
class OSelectorPrivate;
OSelectorPrivate *d;
};
/**
* The OGradientSelector widget allows the user to choose
* from a one-dimensional range of colors which is given as a
* gradient between two colors provided by the programmer.
*/
class OGradientSelector : public OSelector
{
Q_OBJECT
Q_PROPERTY( QColor firstColor READ firstColor WRITE setFirstColor )
Q_PROPERTY( QColor secondColor READ secondColor WRITE setSecondColor )
Q_PROPERTY( QString firstText READ firstText WRITE setFirstText )
Q_PROPERTY( QString secondText READ secondText WRITE setSecondText )
public:
/**
* Constructs a horizontal color selector which
* contains a gradient between white and black.
*/
OGradientSelector( QWidget *parent=0, const char *name=0 );
/**
* Constructs a colors selector with orientation o which
* contains a gradient between white and black.
*/
OGradientSelector( Orientation o, QWidget *parent=0, const char *name=0 );
/**
* Destructs the widget.
*/
~OGradientSelector();
/**
* Sets the two colors which span the gradient.
*/
void setColors( const QColor &col1, const QColor &col2 )
{ color1 = col1; color2 = col2; update();}
void setText( const QString &t1, const QString &t2 )
{ text1 = t1; text2 = t2; update(); }
/**
* Set each color on its own.
*/
void setFirstColor( const QColor &col )
{ color1 = col; update(); }
void setSecondColor( const QColor &col )
{ color2 = col; update(); }
/**
* Set each description on its own
*/
void setFirstText( const QString &t )
{ text1 = t; update(); }
void setSecondText( const QString &t )
{ text2 = t; update(); }
const QColor firstColor() const
{ return color1; }
const QColor secondColor() const
{ return color2; }
const QString firstText() const
{ return text1; }
const QString secondText() const
{ return text2; }
protected:
/**
* @reimplemented
*/
virtual void drawContents( QPainter * );
/**
* @reimplemented
*/
virtual QSize minimumSize() const
{ return sizeHint(); }
private:
void init();
QColor color1;
QColor color2;
QString text1;
QString text2;
private:
class OGradientSelectorPrivate;
OGradientSelectorPrivate *d;
};
/**
* Widget for Hue/Saturation selection.
* The actual values can be fetched using the inherited xValue and yValue
* methods.
*
* @see OXYSelector, OValueSelector, OColorDialog
* @author Martin Jones (mjones@kde.org)
* @version $Id$
*/
class OHSSelector : public OXYSelector
{
Q_OBJECT
public:
/**
* Constructs a hue/saturation selection widget.
*/
OHSSelector( QWidget *parent=0, const char *name=0 );
protected:
/**
* Draws the contents of the widget on a pixmap,
* which is used for buffering.
*/
virtual void drawPalette( QPixmap *pixmap );
/**
* @reimplemented
*/
virtual void resizeEvent( QResizeEvent * );
/**
* Reimplemented from OXYSelector. This drawing is
* buffered in a pixmap here. As real drawing
* routine, drawPalette() is used.
*/
virtual void drawContents( QPainter *painter );
private:
void updateContents();
QPixmap pixmap;
private:
class OHSSelectorPrivate;
OHSSelectorPrivate *d;
};
class OValueSelectorPrivate;
/**
* Widget for color value selection.
*
* @see OHSSelector, OColorDialog
* @author Martin Jones (mjones@kde.org)
* @version $Id$
*/
class OValueSelector : public OSelector
{
Q_OBJECT
public:
/**
* Constructs a widget for color selection.
*/
OValueSelector( QWidget *parent=0, const char *name=0 );
/**
* Constructs a widget for color selection with a given orientation
*/
OValueSelector( Orientation o, QWidget *parent = 0, const char *name = 0 );
int hue() const
{ return _hue; }
void setHue( int h )
{ _hue = h; }
int saturation() const
{ return _sat; }
void setSaturation( int s )
{ _sat = s; }
void updateContents();
protected:
/**
* Draws the contents of the widget on a pixmap,
* which is used for buffering.
*/
virtual void drawPalette( QPixmap *pixmap );
/**
* @reimplemented
*/
virtual void resizeEvent( QResizeEvent * );
/**
* Reimplemented from OSelector. The drawing is
* buffered in a pixmap here. As real drawing
* routine, drawPalette() is used.
*/
virtual void drawContents( QPainter *painter );
private:
int _hue;
int _sat;
QPixmap pixmap;
private:
class OValueSelectorPrivate;
OValueSelectorPrivate *d;
};
class OColor : public QColor
{
public:
OColor();
OColor( const OColor &col);
OColor( const QColor &col);
OColor& operator=( const OColor& col);
bool operator==( const OColor& col) const;
void setHsv(int _h, int _s, int _v);
void setRgb(int _r, int _g, int _b);
void rgb(int *_r, int *_g, int *_b) const;
void hsv(int *_h, int *_s, int *_v) const;
protected:
int h;
int s;
int v;
int r;
int g;
int b;
private:
class OColorPrivate;
OColorPrivate *d;
};
+}
+}
#endif // __OSELECT_H__
diff --git a/libopie2/opieui/oseparator.cpp b/libopie2/opieui/oseparator.cpp
index b93c225..bbc4381 100644
--- a/libopie2/opieui/oseparator.cpp
+++ b/libopie2/opieui/oseparator.cpp
@@ -1,127 +1,129 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/oseparator.h>
/* QT */
+using namespace Opie::Core;
+using namespace Opie::Ui;
OSeparator::OSeparator(QWidget* parent, const char* name, WFlags f)
: QFrame(parent, name, f)
{
setLineWidth(1);
setMidLineWidth(0);
setOrientation( HLine );
}
OSeparator::OSeparator(int orientation, QWidget* parent, const char* name, WFlags f)
: QFrame(parent, name, f)
{
setLineWidth(1);
setMidLineWidth(0);
setOrientation( orientation );
}
void OSeparator::setOrientation(int orientation)
{
switch(orientation)
{
case Vertical:
case VLine:
setFrameStyle( QFrame::VLine | QFrame::Sunken );
setMinimumSize(2, 0);
break;
default:
owarn << "OSeparator::setOrientation(): invalid orientation, using default orientation HLine" << oendl;
case Horizontal:
case HLine:
setFrameStyle( QFrame::HLine | QFrame::Sunken );
setMinimumSize(0, 2);
break;
}
}
int OSeparator::orientation() const
{
if ( frameStyle() & VLine )
return VLine;
if ( frameStyle() & HLine )
return HLine;
return 0;
}
void OSeparator::drawFrame(QPainter *p)
{
QPoint p1, p2;
QRect r = frameRect();
const QColorGroup & g = colorGroup();
if ( frameStyle() & HLine ) {
p1 = QPoint( r.x(), r.height()/2 );
p2 = QPoint( r.x()+r.width(), p1.y() );
}
else {
p1 = QPoint( r.x()+r.width()/2, 0 );
p2 = QPoint( p1.x(), r.height() );
}
#if QT_VERSION < 300
style().drawSeparator( p, p1.x(), p1.y(), p2.x(), p2.y(), g, true, 1, midLineWidth() );
#else
QStyleOption opt( lineWidth(), midLineWidth() );
style().drawPrimitive( QStyle::PE_Separator, p, QRect( p1, p2 ), g, QStyle::Style_Sunken, opt );
#endif
}
QSize OSeparator::sizeHint() const
{
if ( frameStyle() & VLine )
return QSize(2, 0);
if ( frameStyle() & HLine )
return QSize(0, 2);
return QSize(-1, -1);
}
diff --git a/libopie2/opieui/oseparator.h b/libopie2/opieui/oseparator.h
index e59b3f4..6fc4344 100644
--- a/libopie2/opieui/oseparator.h
+++ b/libopie2/opieui/oseparator.h
@@ -1,90 +1,95 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
Copyright (C) 1997 Michael Roth <mroth@wirlweb.de>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OSEPARATOR_H
#define OSEPARATOR_H
#include <qframe.h>
+namespace Opie {
+namespace Ui {
+
/**
* Standard horizontal or vertical separator.
*
* @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
* @author Michael Roth <mroth@wirlweb.de>
* @version $Id$
*/
class OSeparator : public QFrame
{
Q_OBJECT
Q_PROPERTY( int orientation READ orientation WRITE setOrientation )
public:
/**
* Constructor.
**/
OSeparator(QWidget* parent=0, const char* name=0, WFlags f=0);
/**
* Constructor.
*
* @param orientation Set the orientation of the separator.
* Possible values are HLine or Horizontal and VLine or Vertical.
**/
OSeparator(int orientation, QWidget* parent=0, const char* name=0,
WFlags f=0);
/**
* Returns the orientation of the separator.
*
* Possible values are VLine and HLine.
**/
int orientation() const;
/**
* Set the orientation of the separator to @p orient
*
* Possible values are VLine and HLine.
*/
void setOrientation(int orient);
/**
* The recommended height (width) for a horizontal (vertical) separator.
**/
virtual QSize sizeHint() const;
protected:
virtual void drawFrame( QPainter * );
private:
class OSeparatorPrivate* d;
};
+}
+}
#endif // OSEPARATOR_H
diff --git a/libopie2/opieui/otabbar.cpp b/libopie2/opieui/otabbar.cpp
index cd3a34b..a62e18b 100644
--- a/libopie2/opieui/otabbar.cpp
+++ b/libopie2/opieui/otabbar.cpp
@@ -1,83 +1,83 @@
/*
                This file is part of the Opie Project
              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/otabbar.h>
-using namespace Opie;
+using namespace Opie::Ui;
OTabBar::OTabBar( QWidget *parent , const char *name )
:QTabBar( parent, name )
{}
void OTabBar::paintLabel( QPainter* p, const QRect& br, QTab* t, bool has_focus ) const
{
QRect r = br;
if ( t->iconset)
{
QIconSet::Mode mode = (t->enabled && isEnabled()) ? QIconSet::Normal : QIconSet::Disabled;
if ( mode == QIconSet::Normal && has_focus )
{
mode = QIconSet::Active;
}
QPixmap pixmap = t->iconset->pixmap( QIconSet::Small, mode );
int pixw = pixmap.width();
int pixh = pixmap.height();
r.setLeft( r.left() + pixw + 2 );
p->drawPixmap( br.left()+2, br.center().y()-pixh/2, pixmap );
}
QRect tr = r;
if ( t->id == currentTab() )
{
tr.setBottom( tr.bottom() - style().defaultFrameWidth() );
}
if ( t->enabled && isEnabled() )
{
p->setPen( colorGroup().foreground() );
p->drawText( tr, AlignCenter | ShowPrefix, t->label );
}
else if ( style() == MotifStyle )
{
p->setPen( palette().disabled().foreground() );
p->drawText( tr, AlignCenter | ShowPrefix, t->label );
}
else
{
p->setPen( colorGroup().light() );
QRect wr = tr;
wr.moveBy( 1, 1 );
p->drawText( wr, AlignCenter | ShowPrefix, t->label );
p->setPen( palette().disabled().foreground() );
p->drawText( tr, AlignCenter | ShowPrefix, t->label );
}
}
diff --git a/libopie2/opieui/otabbar.h b/libopie2/opieui/otabbar.h
index 2f35c85..925ae96 100644
--- a/libopie2/opieui/otabbar.h
+++ b/libopie2/opieui/otabbar.h
@@ -1,85 +1,86 @@
/*
                This file is part of the Opie Project
              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTABBAR_H
#define OTABBAR_H
/* QT */
#include <qtabbar.h>
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
/**
* @class OTabBar
* @brief The OTabBar class is a derivative of QTabBar.
*
* OTabBar is a derivation of TrollTech's QTabBar which provides
* a row of tabs for selection. The only difference between this
* class and QTabBar is that there is no dotted line box around
* the label of the tab with the current focus.
*/
class OTabBar : public QTabBar
{
Q_OBJECT
public:
/**
* @fn OTabBar( QWidget *parent = 0, const char *name = 0 )
* @brief Object constructor.
*
* @param parent Pointer to parent of this control.
* @param name Name of control.
*
* Constructs a new OTabBar control with parent and name.
*/
OTabBar( QWidget * = 0, const char * = 0 );
protected:
/**
* @fn paintLabel( QPainter* p, const QRect& br , QTab* t, bool has_focus)const
* @brief Internal function to draw a tab's label.
*
* @param p Pointer to QPainter used for drawing.
* @param br QRect providing region to draw label in.
* @param t Tab to draw label for.
* @param has_focus Boolean value not used, retained for compatibility reasons.
*/
void paintLabel( QPainter *, const QRect &, QTab *, bool ) const;
private:
class Private;
Private *d;
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/otabinfo.h b/libopie2/opieui/otabinfo.h
index 4a6ce14..426c45a 100644
--- a/libopie2/opieui/otabinfo.h
+++ b/libopie2/opieui/otabinfo.h
@@ -1,140 +1,141 @@
/*
                This file is part of the Opie Project
              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTABINFO_H
#define OTABINFO_H
/* QT */
#include <qlist.h>
#include <qstring.h>
class QWidget;
-namespace Opie
-{
+namespace Opie{
+namespace Ui {
/**
* @class OTabInfo
* @brief The OTabInfo class is used internally by OTabWidget to keep track
* of widgets added to the control.
*
* OTabInfo provides the following information about a widget added to an
* OTabWidget control:
*
* ID - integer tab bar ID
* Control - QWidget pointer to child widget
* Label - QString text label for OTabWidget selection control
* Icon - QString name of icon file
*/
class OTabInfo
{
public:
/**
* @fn OTabInfo()
* @brief Object constructor.
*
* @param parent Pointer to parent of this control.
* @param name Name of control.
* @param s Style of widget selection control.
* @param p Position of the widget selection control.
*/
OTabInfo() : i( -1 ), c( 0 ), p( 0 ), l( QString::null ) {}
/**
* @fn OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
* @brief Object constructor.
*
* @param id TabBar identifier for widget.
* @param control QWidget pointer to widget.
* @param icon QString name of icon file.
* @param label QString text label for OTabWidget selection control.
*/
OTabInfo( int id, QWidget *control, const QString &icon, const QString &label )
: i( id ), c( control ), p( icon ), l( label ) {}
/**
* @fn id()const
* @brief Returns TabBar ID.
*/
int id() const { return i; }
/**
* @fn label()const
* @brief Returns text label for widget.
*/
const QString &label() const { return l; }
/**
* @fn setLabel( const QString &label )
* @brief Set label for tab.
*
* @param label QString text label for OTabWidget selection control.
*/
void setLabel( const QString &label ) { l = label; }
/**
* @fn control()const
* @brief Returns pointer to widget.
*/
QWidget *control() const { return c; }
/**
* @fn icon()const
* @brief Returns name of icon file.
*/
const QString &icon() const { return p; }
/**
* @fn setIcon( const QString &icon )
* @brief Set icon for tab.
*
* @param icon QString name of icon file.
*/
void setIcon( const QString &icon ) { p = icon; }
private:
int i;
QWidget *c;
QString p;
QString l;
class Private;
Private *d;
};
/**
* @class OTabInfoList
* @brief A list of OTabInfo objects used by OTabWidget.
*/
typedef QList<OTabInfo> OTabInfoList;
-};
+}
+}
#endif
diff --git a/libopie2/opieui/otabwidget.cpp b/libopie2/opieui/otabwidget.cpp
index f47c90b..a9f7da9 100644
--- a/libopie2/opieui/otabwidget.cpp
+++ b/libopie2/opieui/otabwidget.cpp
@@ -1,423 +1,423 @@
/*
                This file is part of the Opie Project
              Copyright (c) 2002 Dan Williams <williamsdr@acm.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/otabwidget.h>
/* OPIE */
#include <qpe/applnk.h>
#include <qpe/config.h>
#include <qpe/resource.h>
#include <opie2/otabbar.h>
/* QT */
#include <qcombobox.h>
#include <qwidgetstack.h>
-using namespace Opie;
+using namespace Opie::Ui;
OTabWidget::OTabWidget( QWidget *parent, const char *name, TabStyle s, TabPosition p )
: QWidget( parent, name )
{
if ( s == Global )
{
Config config( "qpe" );
config.setGroup( "Appearance" );
s = ( TabStyle ) config.readNumEntry( "TabStyle", (int) IconTab );
if ( s <= Global || s > IconList)
{
s = IconTab;
}
QString pos = config.readEntry( "TabPosition", "Top");
if ( pos == "Bottom" )
{
p = Bottom;
}
else
{
p = Top;
}
}
widgetStack = new QWidgetStack( this, "widgetstack" );
widgetStack->setFrameStyle( QFrame::NoFrame );
widgetStack->setLineWidth( style().defaultFrameWidth() );
tabBarStack = new QWidgetStack( this, "tabbarstack" );
tabBar = new OTabBar( tabBarStack, "tabbar" );
tabBarStack->addWidget( tabBar, 0 );
connect( tabBar, SIGNAL( selected(int) ), this, SLOT( slotTabBarSelected(int) ) );
tabList = new QComboBox( false, tabBarStack, "tablist" );
tabBarStack->addWidget( tabList, 1 );
connect( tabList, SIGNAL( activated(int) ), this, SLOT( slotTabListSelected(int) ) );
tabBarPosition = p;
setTabStyle( s );
setTabPosition( p );
currTab= 0x0;
}
OTabWidget::~OTabWidget()
{}
void OTabWidget::addTab( QWidget *child, const QString &icon, const QString &label )
{
QPixmap iconset = loadSmooth( icon );
QTab *tab = new QTab();
if ( tabBarStyle == IconTab )
{
tab->label = QString::null;
}
else
{
tab->label = label;
}
if ( tabBarStyle == IconTab || tabBarStyle == IconList )
{
tab->iconset = new QIconSet( iconset );
}
int tabid = tabBar->addTab( tab );
if ( tabBarStyle == IconTab || tabBarStyle == IconList )
{
tabList->insertItem( iconset, label, -1 );
}
else
{
tabList->insertItem( label );
}
widgetStack->addWidget( child, tabid );
widgetStack->raiseWidget( child );
widgetStack->setFrameStyle( QFrame::StyledPanel | QFrame::Raised );
OTabInfo *tabinfo = new OTabInfo( tabid, child, icon, label );
tabs.append( tabinfo );
selectTab( tabinfo );
}
void OTabWidget::removePage( QWidget *childwidget )
{
if ( childwidget )
{
OTabInfo *tab = tabs.first();
while ( tab && tab->control() != childwidget )
{
tab = tabs.next();
}
if ( tab && tab->control() == childwidget )
{
tabBar->setTabEnabled( tab->id(), FALSE );
tabBar->removeTab( tabBar->tab( tab->id() ) );
int i = 0;
while ( i < tabList->count() && tabList->text( i ) != tab->label() )
{
i++;
}
if ( tabList->text( i ) == tab->label() )
{
tabList->removeItem( i );
}
widgetStack->removeWidget( childwidget );
tabs.remove( tab );
delete tab;
currTab = tabs.current();
if ( !currTab )
{
widgetStack->setFrameStyle( QFrame::NoFrame );
}
setUpLayout();
}
}
}
void OTabWidget::changeTab( QWidget *widget, const QString &iconset, const QString &label)
{
OTabInfo *currtab = tabs.first();
while ( currtab && currtab->control() != widget )
{
currtab = tabs.next();
}
if ( currtab && currtab->control() == widget )
{
QTab *tab = tabBar->tab( currtab->id() );
QPixmap icon( loadSmooth( iconset ) );
tab->setText( label );
if ( tabBarStyle == IconTab )
tab->setIconSet( icon );
int i = 0;
while ( i < tabList->count() && tabList->text( i ) != currtab->label() )
{
i++;
}
if ( i < tabList->count() && tabList->text( i ) == currtab->label() )
{
if ( tabBarStyle == IconTab || tabBarStyle == IconList )
{
tabList->changeItem( icon, label, i );
}
else
{
tabList->changeItem( label, i );
}
}
currtab->setLabel( label );
currtab->setIcon( iconset );
}
setUpLayout();
}
void OTabWidget::setCurrentTab( QWidget *childwidget )
{
OTabInfo *currtab = tabs.first();
while ( currtab && currtab->control() != childwidget )
{
currtab = tabs.next();
}
if ( currtab && currtab->control() == childwidget )
{
selectTab( currtab );
}
}
void OTabWidget::setCurrentTab( const QString &tabname )
{
OTabInfo *newtab = tabs.first();
while ( newtab && newtab->label() != tabname )
{
newtab = tabs.next();
}
if ( newtab && newtab->label() == tabname )
{
selectTab( newtab );
}
}
void OTabWidget::setCurrentTab(int tabindex)
{
OTabInfo *newtab = tabs.first();
while ( newtab && newtab->id() != tabindex )
{
newtab = tabs.next();
}
if ( newtab && newtab->id() == tabindex )
{
selectTab( newtab );
}
}
OTabWidget::TabStyle OTabWidget::tabStyle() const
{
return tabBarStyle;
}
void OTabWidget::setTabStyle( TabStyle s )
{
tabBarStyle = s;
if ( tabBarStyle == TextTab || tabBarStyle == IconTab )
{
QTab *currtab;
for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
{
currtab = tabBar->tab( tabinfo->id() );
if ( tabBarStyle == IconTab )
{
currtab->iconset = new QIconSet( loadSmooth( tabinfo->icon() ) );
if ( tabinfo == currTab )
currtab->setText( tabinfo->label() );
else
currtab->setText( QString::null );
}
else
{
currtab->iconset = 0x0;
currtab->setText( tabinfo->label() );
}
}
tabBarStack->raiseWidget( tabBar );
}
else if ( tabBarStyle == TextList || tabBarStyle == IconList )
{
tabList->clear();
for ( OTabInfo *tabinfo = tabs.first(); tabinfo; tabinfo = tabs.next() )
{
if ( tabBarStyle == IconList )
{
tabList->insertItem( loadSmooth( tabinfo->icon() ), tabinfo->label() );
}
else
{
tabList->insertItem( tabinfo->label() );
}
}
tabBarStack->raiseWidget( tabList );
}
setUpLayout();
}
OTabWidget::TabPosition OTabWidget::tabPosition() const
{
return tabBarPosition;
}
void OTabWidget::setTabPosition( TabPosition p )
{
tabBarPosition = p;
if ( tabBarPosition == Top )
{
tabBar->setShape( QTabBar::RoundedAbove );
}
else
{
tabBar->setShape( QTabBar::RoundedBelow );
}
setUpLayout();
}
void OTabWidget::slotTabBarSelected( int id )
{
OTabInfo *newtab = tabs.first();
while ( newtab && newtab->id() != id )
{
newtab = tabs.next();
}
if ( newtab && newtab->id() == id )
{
selectTab( newtab );
}
}
void OTabWidget::slotTabListSelected( int index )
{
OTabInfo *newtab = tabs.at( index );
if ( newtab )
{
selectTab( newtab );
}
}
QPixmap OTabWidget::loadSmooth( const QString &name )
{
QPixmap p;
p.convertFromImage( Resource::loadImage( name ).smoothScale( AppLnk::smallIconSize(), AppLnk::smallIconSize() ) );
return p;
}
void OTabWidget::selectTab( OTabInfo *tab )
{
if ( tabBarStyle == IconTab )
{
if ( currTab )
{
tabBar->tab( currTab->id() )->setText( QString::null );
setUpLayout();
}
tabBar->tab( tab->id() )->setText( tab->label() );
tabBar->setCurrentTab( tab->id() );
setUpLayout();
tabBar->update();
}
else
{
tabBar->setCurrentTab( tab->id() );
}
widgetStack->raiseWidget( tab->control() );
emit currentChanged( tab->control() );
currTab = tab;
}
void OTabWidget::setUpLayout()
{
tabBar->layoutTabs();
QSize t( tabBarStack->sizeHint() );
if ( tabBarStyle == IconTab )
{
if ( t.width() > width() )
t.setWidth( width() );
}
else
{
t.setWidth( width() );
}
int lw = widgetStack->lineWidth();
if ( tabBarPosition == Bottom )
{
tabBarStack->setGeometry( QMAX(0, lw-2), height() - t.height() - lw, t.width(), t.height() );
widgetStack->setGeometry( 0, 0, width(), height()-t.height()+QMAX(0, lw-2) );
}
else
{
tabBarStack->setGeometry( QMAX(0, lw-2), 0, t.width(), t.height() );
widgetStack->setGeometry( 0, t.height()-lw, width(), height()-t.height()+QMAX( 0, lw-2 ) );
}
if ( autoMask() )
updateMask();
}
QSize OTabWidget::sizeHint() const
{
QSize s( widgetStack->sizeHint() );
QSize t( tabBarStack->sizeHint() );
return QSize( QMAX( s.width(), t.width() ), s.height() + t.height() );
}
void OTabWidget::resizeEvent( QResizeEvent * )
{
setUpLayout();
}
int OTabWidget::currentTab()
{
if ( currTab )
{
return currTab->id();
}
return -1;
}
QWidget* OTabWidget::currentWidget()const
{
if ( currTab )
{
return currTab->control();
}
return 0;
}
diff --git a/libopie2/opieui/otabwidget.h b/libopie2/opieui/otabwidget.h
index 092f22c..6a64b7d 100644
--- a/libopie2/opieui/otabwidget.h
+++ b/libopie2/opieui/otabwidget.h
@@ -1,292 +1,292 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2002 Dan Williams <williamsdr@acm.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTABWIDGET_H
#define OTABWIDGET_H
/* OPIE */
#include <opie2/otabinfo.h>
/* QT */
#include <qwidget.h>
#include <qlist.h>
-using namespace Opie;
class QComboBox;
class QPixmap;
class QTabBar;
class QWidgetStack;
-namespace Opie
-{
+namespace Opie {
+namespace Ui {
class OTabBar;
/**
* @class OTabWidget
* @brief The OTabWidget class provides a stack of widgets.
*
* OTabWidget is a derivation of TrollTech's QTabWidget which provides
* a stack of widgets. Widgets can be selected using either a tab bar or
* drop down list box.
*
* The normal way to use OTabWidget is to do the following in the
* constructor:
* - Create a OTabWidget.
* - Create a QWidget for each of the pages in the control, insert
* children into it, set up geometry management for it, and use addTab()
* to add the widget.
*/
class OTabWidget : public QWidget
{
Q_OBJECT
public:
/**
* @enum TabStyle
* @brief Defines how the widget selection control is displayed.
*
* Valid values:
* - Global: use globally selected options (qpe.conf - TabStyle & TabPosition)
* - TextTab: Tabbed widget selection with text labels
* - IconTab: Tabbed widget selection with icon labels, text label for active widget
* (similar to Opie launcher)
* - TextList: Drop down list widget selection with text labels
* - IconList: Drop down list widget selection with icon & text labels
*/
enum TabStyle { Global, TextTab, IconTab, TextList, IconList };
/**
* @enum TabPosition
* @brief Defines where the widget selection control is drawn.
*
* Valid values:
* - Top: Widget selection control is drawn above widgets
* - Bottom: Widget selection control is drawn below widgets
*/
enum TabPosition { Top, Bottom };
/**
* @fn OTabWidget( QWidget *parent = 0, const char *name = 0, TabStyle s = Global, TabPosition p = Top )
* @brief Object constructor.
*
* @param parent Pointer to parent of this control.
* @param name Name of control.
* @param s Style of widget selection control.
* @param p Position of the widget selection control.
*
* Constructs a new OTabWidget control with parent and name. The style and position parameters
* determine how the widget selection control will be displayed.
*/
OTabWidget( QWidget * = 0, const char * = 0, TabStyle = Global, TabPosition = Top );
/**
* @fn ~OTabWidget()
* @brief Object destructor.
*/
~OTabWidget();
/**
* @fn addTab( QWidget *child, const QString &icon, const QString &label )
* @brief Add new widget to control.
*
* @param child Widget control.
* @param icon Path to icon.
* @param label Text label.
*/
void addTab( QWidget *, const QString &, const QString & );
/**
* @fn removePage( QWidget *widget )
* @brief Remove widget from control. Does not delete widget.
*
* @param widget Widget control to be removed.
*/
void removePage( QWidget * );
/**
* @fn changeTab( QWidget *widget, const QString &icon, const QString &label )
* @brief Change text and/or icon for existing tab
*
* @param child Widget control.
* @param icon Path to icon.
* @param label Text label.
*/
void changeTab( QWidget *, const QString &, const QString & );
/**
* @fn tabStyle()const
* @brief Returns current widget selection control style.
*/
TabStyle tabStyle() const;
/**
* @fn setTabStyle( TabStyle s )
* @brief Set the current widget selection control style.
*
* @param s New style to be used.
*/
void setTabStyle( TabStyle );
/**
* @fn tabPosition()const
* @brief Returns current widget selection control position.
*/
TabPosition tabPosition() const;
/**
* @fn setTabPosition( TabPosition p )
* @brief Set the current widget selection control position.
*
* @param p New position of widget selection control.
*/
void setTabPosition( TabPosition );
/**
* @fn setCurrentTab( QWidget *childwidget )
* @brief Selects and brings to top the desired widget by using widget pointer.
*
* @param childwidget Widget to select.
*/
void setCurrentTab( QWidget * );
/**
* @fn setCurrentTab( const QString &tabname )
* @brief Selects and brings to top the desired widget, by using label.
*
* @param tabname Text label for widget to select.
*/
void setCurrentTab( const QString & );
/**
* @fn setCurrentTab( int )
* @brief Selects and brings to top the desired widget, by using id.
*
* @param tab id for widget to select.
*/
void setCurrentTab(int);
/**
* @fn sizeHint()const
* @brief Reimplemented for internal purposes.
*/
QSize sizeHint() const;
/**
* @fn currentTab( )
* @brief returns current tab id.
*/
// ### make const
int currentTab()/* const */;
/**
* @brief returns the current page of the active tab
*
* @since 1.2
*/
QWidget* currentWidget()const;
protected:
/**
* @fn resizeEvent( QResizeEvent * )
* @brief Reimplemented for internal purposes.
*/
void resizeEvent( QResizeEvent * );
private:
OTabInfoList tabs;
OTabInfo *currTab;
TabStyle tabBarStyle;
TabPosition tabBarPosition;
QWidgetStack *tabBarStack;
OTabBar *tabBar;
QComboBox *tabList;
QWidgetStack *widgetStack;
class Private;
Private* d;
/**
* @fn loadSmooth( const QString &name )
* @brief Loads icon for widget.
*
* @param name Name of icon image file.
*/
QPixmap loadSmooth( const QString & );
/**
* @fn selectTab( OTabInfo *tab )
* @brief Internal function to select desired widget.
*
* @param tab Pointer to data for widget.
*/
void selectTab( OTabInfo * );
/**
* @fn setUpLayout()
* @brief Internal function to adjust layout.
*/
void setUpLayout();
signals:
/**
* @fn currentChanegd( QWidget *widget )
* @brief This signal is emitted whenever the widget has changed.
*
* @param widget Pointer to new current widget.
*/
void currentChanged( QWidget * );
private slots:
/**
* @fn slotTabBarSelected( int id )
* @brief Slot which is called when a tab is selected.
*
* @param id ID of widget selected.
*/
void slotTabBarSelected( int );
/**
* @fn slotTabListSelected( int index )
* @brief Slot which is called when a drop down selection is made.
*
* @param id Index of widget selected.
*/
void slotTabListSelected( int );
};
-};
+}
+}
#endif
diff --git a/libopie2/opieui/otaskbarapplet.cpp b/libopie2/opieui/otaskbarapplet.cpp
index a67356d..b5268f0 100644
--- a/libopie2/opieui/otaskbarapplet.cpp
+++ b/libopie2/opieui/otaskbarapplet.cpp
@@ -1,32 +1,82 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+#include <opie2/otaskbarapplet.h>
+
+#include <qpe/qpeapplication.h>
+#include <qframe.h>
+
+using namespace Opie::Ui;
+
+
+/**
+ * \todo no example yet!!!
+ * If you want to implement an Applet for the Opie Taskbar
+ * use this interface.
+ * The only specail thing about applets is that you need to build
+ * it as plugin/library and do EXPORT_OPIE_APPLET_v1( YourApplet )
+ * at the bottom of your application. This takes care of
+ * the activation and implementing the TaskbarAppletInterface.
+ * You also need to add a static int position() functions to your
+ * application.
+ * \code
+ * class MyApplet : public OTaskBarApplet {
+ * public:
+ * static int position() { return 3: }
+ * void doStuff() {
+ * popup( myWidget );
+ * }
+ * };
+ * EXPORT_OPIE_APPLET_v1( MyApplet )
+ * \endcode
+ *
+ * @author Michael Lauer
+ * @version 0.5
+ * @see TaskbarAppletInterface
+ */
+OTaskbarApplet::OTaskbarApplet( QWidget* parent, const char* name )
+ :QWidget( parent, name ){
+ setFixedHeight( 18 );
+ setFixedWidth( 14 );
+}
+
+OTaskbarApplet::~OTaskbarApplet(){
+}
+
+void OTaskbarApplet::popup( QWidget* widget ){
+ QPoint curPos = mapToGlobal( QPoint( 0, 0 ) );
+ int w = widget->sizeHint().width();
+ int x = curPos.x() - (w/2 );
+ if ( (x+w) > QPEApplication::desktop()->width() )
+ x = QPEApplication::desktop()->width()-w;
+ widget->move( x, curPos.y()-widget->sizeHint().height() );
+ widget->show();
+}
-// Empty on purpose until we shipped Opie 1.0 (see otaskbarapplet.h for explanation)
diff --git a/libopie2/opieui/otaskbarapplet.h b/libopie2/opieui/otaskbarapplet.h
index 074367f..0c85ee7 100644
--- a/libopie2/opieui/otaskbarapplet.h
+++ b/libopie2/opieui/otaskbarapplet.h
@@ -1,130 +1,129 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTASKBARAPPLET_H
#define OTASKBARAPPLET_H
#include <qpe/taskbarappletinterface.h>
+#include <qpe/qcom.h>
+#include <qwidget.h>
+
+class QMouseEvent;
+
+namespace Opie {
+namespace Ui {
+namespace Private {
/*======================================================================================
* OTaskbarAppletWrapper
*======================================================================================*/
+class OTaskbarAppletWrapperPrivate;
template<class T> class OTaskbarAppletWrapper : public TaskbarAppletInterface
{
public:
OTaskbarAppletWrapper():_applet( 0 )
{
}
virtual ~OTaskbarAppletWrapper()
{
delete _applet;
}
QRESULT queryInterface( const QUuid& uuid, QUnknownInterface** iface )
{
qDebug( "OTaskbarAppletWrapper::queryInterface()" );
*iface = 0;
if ( uuid == IID_QUnknown )
*iface = this;
else if ( uuid == IID_TaskbarApplet )
*iface = this;
else
return QS_FALSE;
if ( *iface ) (*iface)->addRef();
return QS_OK;
}
Q_REFCOUNT
virtual T* applet( QWidget* parent )
{
if ( !_applet ) _applet = new T( parent );
return _applet;
}
virtual int position() const
{
return T::position();
}
private:
T* _applet;
+ OTaskbarAppletWrapperPrivate *d;
};
-#include <qframe.h>
-#include <qwidget.h>
-#include <qpe/qpeapplication.h>
-
-class QMouseEvent;
-
+}
/*======================================================================================
* OTaskbarApplet
*======================================================================================*/
// Must be inline until after we shipped Opie 1.0
// Having OTaskBarApplet reside in libopieui2 is not possible
// until we link the launcher binary against libopieui2 -
// otherwise the necessary symbols are not present, when
// the dynamic loader [dlopen] tries to resolve an applet which
// inherits OTaskbarApplet
class OTaskbarApplet : public QWidget
{
public:
- OTaskbarApplet( QWidget* parent, const char* name = 0 ):QWidget( parent, name )
- {
- setFixedHeight( 18 );
- setFixedWidth( 14 );
- }
-
- virtual ~OTaskbarApplet()
- {
- }
+ OTaskbarApplet( QWidget* parent, const char* name = 0 );
+ virtual ~OTaskbarApplet();
protected:
- virtual void popup( QWidget* widget )
- {
- QPoint curPos = mapToGlobal( QPoint( 0, 0 ) );
- int w = widget->sizeHint().width();
- int x = curPos.x() - (w/2 );
- if ( (x+w) > QPEApplication::desktop()->width() )
- x = QPEApplication::desktop()->width()-w;
- widget->move( x, curPos.y()-widget->sizeHint().height() );
- widget->show();
- }
+ virtual void popup( QWidget* widget );
+private:
+ class Private;
+ Private *d;
};
+}
+}
+
+#define EXPORT_OPIE_APPLET_v1( AppLet ) \
+ Q_EXPORT_INTERFACE() { \
+ Q_CREATE_INSTANCE( Opie::Ui::Private::OTaskbarAppletWrapper<AppLet> ) \
+ }
#endif
diff --git a/libopie2/opieui/otimepicker.cpp b/libopie2/opieui/otimepicker.cpp
index 66f9ce0..7de0fd3 100644
--- a/libopie2/opieui/otimepicker.cpp
+++ b/libopie2/opieui/otimepicker.cpp
@@ -1,292 +1,301 @@
/*
This file is part of the Opie Project
Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
+/* OPIE */
+#include <opie2/otimepicker.h>
+
/* QT */
+#include <qgroupbox.h>
#include <qlayout.h>
#include <qlineedit.h>
-/* OPIE */
-#include <opie2/otimepicker.h>
-using namespace Opie;
+
+namespace Opie {
+namespace Ui {
/**
* Constructs the widget
* @param parent The parent of the OTimePicker
* @param name The name of the object
* @param fl Window Flags
*/
OTimePicker::OTimePicker(QWidget* parent, const char* name, Qt::WFlags fl)
:QWidget(parent,name,fl)
{
QVBoxLayout *vbox=new QVBoxLayout(this);
OClickableLabel *r;
QString s;
// Hour Row
QWidget *row=new QWidget(this);
QHBoxLayout *l=new QHBoxLayout(row);
vbox->addWidget(row);
for (int i=0; i<24; i++)
{
r=new OClickableLabel(row);
hourLst.append(r);
s.sprintf("%.2d",i);
r->setText(s);
r->setToggleButton(true);
r->setAlignment(AlignHCenter | AlignVCenter);
l->addWidget(r);
connect(r, SIGNAL(toggled(bool)),
this, SLOT(slotHour(bool)));
if (i==11)
{ // Second row
row=new QWidget(this);
l=new QHBoxLayout(row);
vbox->addWidget(row);
}
}
// Minute Row
row=new QWidget(this);
l=new QHBoxLayout(row);
vbox->addWidget(row);
for (int i=0; i<60; i+=5)
{
r=new OClickableLabel(row);
minuteLst.append(r);
s.sprintf("%.2d",i);
r->setText(s);
r->setToggleButton(true);
r->setAlignment(AlignHCenter | AlignVCenter);
l->addWidget(r);
connect(r, SIGNAL(toggled(bool)),
this, SLOT(slotMinute(bool)));
}
}
/**
* This method return the current time
* @return the time
*/
QTime OTimePicker::time()const
{
return tm;
}
void OTimePicker::slotHour(bool b)
{
OClickableLabel *r = (OClickableLabel *) sender();
if (b)
{
QValueListIterator<OClickableLabel *> it;
for (it=hourLst.begin(); it!=hourLst.end(); it++)
{
if (*it != r) (*it)->setOn(false);
else tm.setHMS((*it)->text().toInt(), tm.minute(), 0);
}
emit timeChanged(tm);
}
else
{
r->setOn(true);
}
}
void OTimePicker::slotMinute(bool b)
{
OClickableLabel *r = (OClickableLabel *) sender();
if (b)
{
QValueListIterator<OClickableLabel *> it;
for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
{
if (*it != r) (*it)->setOn(false);
else tm.setHMS(tm.hour(),(*it)->text().toInt(), 0);
}
emit timeChanged(tm);
}
else
{
r->setOn(true);
}
}
/**
* Method to set the time. No signal gets emitted during this method call
* Minutes must be within 5 minutes step starting at 0 ( 0,5,10,15,20... )
* @param t The time to be set
*/
void OTimePicker::setTime( const QTime& t)
{
setTime( t.hour(), t.minute() );
}
/**
* Method to set the time. No signal gets emitted during this method call
* @param h The hour
* @param m The minute. Minutes need to set by 5 minute steps
*/
void OTimePicker::setTime( int h, int m )
{
setHour(h);
setMinute(m);
}
/*
* FIXME round minutes to the 5 minute arrangement -zecke
*/
/**
* Method to set the minutes
* @param m minutes
*/
void OTimePicker::setMinute(int m)
{
QString minute;
minute.sprintf("%.2d",m);
QValueListIterator<OClickableLabel *> it;
for (it=minuteLst.begin(); it!=minuteLst.end(); it++)
{
if ((*it)->text() == minute) (*it)->setOn(true);
else (*it)->setOn(false);
}
tm.setHMS(tm.hour(),m,0);
}
/**
* Method to set the hour
*/
void OTimePicker::setHour(int h)
{
QString hour;
hour.sprintf("%.2d",h);
QValueListIterator<OClickableLabel *> it;
for (it=hourLst.begin(); it!=hourLst.end(); it++)
{
if ((*it)->text() == hour) (*it)->setOn(true);
else (*it)->setOn(false);
}
tm.setHMS(h,tm.minute(),0);
}
/**
* This is a modal Dialog.
*
* @param parent The parent widget
* @param name The name of the object
* @param fl Possible window flags
*/
OTimePickerDialog::OTimePickerDialog ( QWidget* parent, const char* name, WFlags fl )
: OTimePickerDialogBase (parent , name, true , fl)
{
+ m_timePicker = new OTimePicker( GroupBox1, "m_timePicker" );
+ GroupBox1Layout->addWidget( m_timePicker, 0, 0 );
connect ( m_timePicker, SIGNAL( timeChanged(const QTime&) ),
this, SLOT( setTime(const QTime&) ) );
connect ( minuteField, SIGNAL( textChanged(const QString&) ),
this, SLOT ( setMinute(const QString&) ) );
connect ( hourField, SIGNAL( textChanged(const QString&) ),
this, SLOT ( setHour(const QString&) ) );
}
/**
* @return the time
*/
QTime OTimePickerDialog::time()const
{
return m_time;
}
/**
* Set the time to time
* @param time The time to be set
*/
void OTimePickerDialog::setTime( const QTime& time )
{
m_time = time;
m_timePicker->setHour ( time.hour() );
m_timePicker->setMinute( time.minute() );
// Set Textfields
if ( time.hour() < 10 )
hourField->setText( "0" + QString::number( time.hour() ) );
else
hourField->setText( QString::number( time.hour() ) );
if ( time.minute() < 10 )
minuteField->setText( "0" + QString::number( time.minute() ) );
else
minuteField->setText( QString::number( time.minute() ) );
}
/**
* This method takes the current minute and tries to set hour
* to hour. This succeeds if the resulting date is valid
* @param hour The hour as a string
*/
void OTimePickerDialog::setHour ( const QString& hour )
{
if ( QTime::isValid ( hour.toInt(), m_time.minute() , 00 ) )
{
m_time.setHMS ( hour.toInt(), m_time.minute() , 00 );
setTime ( m_time );
}
}
/**
* Method to set a new minute. It tries to convert the string to int and
* if the resulting date is valid a new date is set.
* @see setHour
*/
void OTimePickerDialog::setMinute ( const QString& minute )
{
if ( QTime::isValid ( m_time.hour(), minute.toInt(), 00 ) )
{
m_time.setHMS ( m_time.hour(), minute.toInt(), 00 );
setTime ( m_time );
}
}
+
+}
+}
diff --git a/libopie2/opieui/otimepicker.h b/libopie2/opieui/otimepicker.h
index 2da7773..01bb557 100644
--- a/libopie2/opieui/otimepicker.h
+++ b/libopie2/opieui/otimepicker.h
@@ -1,125 +1,132 @@
/*
This file is part of the Opie Project
Copyright (C) Stefan Eilers <eilers.stefan@epost.de>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OTIMEPICKER_H
#define OTIMEPICKER_H
/* OPIE */
#include <opie2/oclickablelabel.h>
-#include "otimepickerbase.h"
+#include <opie2/otimepickerbase.h>
/* QT */
#include <qwidget.h>
#include <qvaluelist.h>
#include <qdatetime.h>
#include <qdialog.h>
-using namespace Opie;
-// namespace Opie
-// {
+namespace Opie {
+namespace Ui {
/**
* A class to pick time. It uses clickable labels
* internally to allow a quick selection of a time.
* A time can be selected by two clicks of a user
*
* @short A widget to quickly pick a QTime
* @version 1.0
* @see QWidget
* @see QTime
* @author Hakan Ardo, Stefan Eilers
*/
-class OTimePicker: public QWidget
+class OTimePicker : public QWidget
{
Q_OBJECT
public:
OTimePicker(QWidget* parent = 0, const char* name = 0, WFlags fl = 0);
public slots:
void setHour(int h);
void setMinute(int m);
void setTime( const QTime& );
void setTime( int h, int m );
public:
QTime time()const;
private:
QValueList<OClickableLabel *> hourLst;
QValueList<OClickableLabel *> minuteLst;
QTime tm;
struct Private;
Private *d;
private slots:
void slotHour(bool b);
void slotMinute(bool b);
signals:
/**
* gets emitted when the time got changed by the user
*/
void timeChanged(const QTime &);
};
/**
*
* @short A small dialog to pick a time
* @version 1.0
* @author Stefan Eilers
*
**/
class OTimePickerDialog: public OTimePickerDialogBase
{
Q_OBJECT
public:
OTimePickerDialog ( QWidget* parent = 0, const char* name = NULL, WFlags fl = 0 );
~OTimePickerDialog() { };
QTime time()const;
public slots:
void setTime( const QTime& time );
void setHour( const QString& hour );
void setMinute( const QString& minute );
private:
+ OTimePicker *m_timePicker;
QTime m_time;
class Private;
Private* d;
};
-// };
+}
+}
+/* for Qt2 */
+#if ( QT_VERSION-0 >= 0x030000 )
+#error "Fix the UI File to use namespaces"
+#else
+typedef Opie::Ui::OTimePicker OUIOTimePicker;
+#endif
#endif
diff --git a/libopie2/opieui/otimepickerbase.ui b/libopie2/opieui/otimepickerbase.ui
index 3e7f2fb..c2eb7c5 100644
--- a/libopie2/opieui/otimepickerbase.ui
+++ b/libopie2/opieui/otimepickerbase.ui
@@ -1,292 +1,256 @@
<!DOCTYPE UI><UI>
<class>OTimePickerDialogBase</class>
<widget>
<class>QDialog</class>
<property stdset="1">
<name>name</name>
<cstring>OTimePickerDialogBase</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>210</width>
+ <width>182</width>
<height>137</height>
</rect>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>1</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>caption</name>
<string>OTimePickerDialogBase</string>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<vbox>
<property stdset="1">
<name>margin</name>
<number>5</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>4</number>
</property>
<widget>
<class>QFrame</class>
<property stdset="1">
<name>name</name>
<cstring>Frame10</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>1</hsizetype>
<vsizetype>7</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>frameShape</name>
<enum>NoFrame</enum>
</property>
<property stdset="1">
<name>frameShadow</name>
<enum>Raised</enum>
</property>
<property>
<name>layoutMargin</name>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>2</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<spacer>
<property>
<name>name</name>
<cstring>Spacer4</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>MinimumExpanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
<widget>
<class>QFrame</class>
<property stdset="1">
<name>name</name>
<cstring>Frame4</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>4</hsizetype>
<vsizetype>4</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>frameShape</name>
<enum>Box</enum>
</property>
<property stdset="1">
<name>frameShadow</name>
<enum>Sunken</enum>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
</property>
<hbox>
<property stdset="1">
<name>margin</name>
<number>4</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>Time:</string>
</property>
</widget>
<widget>
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>hourField</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>4</hsizetype>
<vsizetype>0</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>alignment</name>
<set>AlignHCenter</set>
</property>
<property>
<name>hAlign</name>
</property>
</widget>
<widget>
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1_2</cstring>
</property>
<property stdset="1">
<name>font</name>
<font>
<bold>1</bold>
</font>
</property>
<property stdset="1">
<name>text</name>
<string>:</string>
</property>
</widget>
<widget>
<class>QLineEdit</class>
<property stdset="1">
<name>name</name>
<cstring>minuteField</cstring>
</property>
<property stdset="1">
<name>alignment</name>
<set>AlignHCenter</set>
</property>
<property>
<name>hAlign</name>
</property>
</widget>
</hbox>
</widget>
<spacer>
<property>
<name>name</name>
<cstring>Spacer5</cstring>
</property>
<property stdset="1">
<name>orientation</name>
<enum>Horizontal</enum>
</property>
<property stdset="1">
<name>sizeType</name>
<enum>MinimumExpanding</enum>
</property>
<property>
<name>sizeHint</name>
<size>
<width>20</width>
<height>20</height>
</size>
</property>
</spacer>
</hbox>
</widget>
<widget>
<class>QGroupBox</class>
<property stdset="1">
<name>name</name>
<cstring>GroupBox1</cstring>
</property>
<property stdset="1">
<name>sizePolicy</name>
<sizepolicy>
<hsizetype>3</hsizetype>
<vsizetype>3</vsizetype>
</sizepolicy>
</property>
<property stdset="1">
<name>margin</name>
<number>0</number>
</property>
<property stdset="1">
<name>title</name>
<string>Pick Time:</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
- <widget row="0" column="0" >
- <class>OTimePicker</class>
- <property stdset="1">
- <name>name</name>
- <cstring>m_timePicker</cstring>
- </property>
- <property stdset="1">
- <name>sizePolicy</name>
- <sizepolicy>
- <hsizetype>3</hsizetype>
- <vsizetype>3</vsizetype>
- </sizepolicy>
- </property>
- </widget>
</grid>
</widget>
</vbox>
</widget>
-<customwidgets>
- <customwidget>
- <class>OTimePicker</class>
- <header location="local">otimepicker.h</header>
- <sizehint>
- <width>-1</width>
- <height>-1</height>
- </sizehint>
- <container>0</container>
- <sizepolicy>
- <hordata>7</hordata>
- <verdata>1</verdata>
- </sizepolicy>
- <pixmap>image0</pixmap>
- </customwidget>
-</customwidgets>
-<images>
- <image>
- <name>image0</name>
- <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1ddec44f503c0ae2a154410f53d0ed20e2bf6bdb656dd6861dd23d9a66591b0587fd1654235ebded6f0edcd53e419d87ae7b1f4f9b8f906d0bfe012317426a70b07bdc2f3ec77f8ed6b89559061a0343d06a124cc105596482585094bc0ae599b04646c9018926491b2205e140c485cace25755c175d0a967b622ff900b8cc9c7d29af594ea722d589167f813aa852ba07d94b9dce296e883fe7bb163f23896753</data>
- </image>
-</images>
</UI>
diff --git a/libopie2/opieui/oversatileview.cpp b/libopie2/opieui/oversatileview.cpp
index 78154b7..f6c6410 100644
--- a/libopie2/opieui/oversatileview.cpp
+++ b/libopie2/opieui/oversatileview.cpp
@@ -1,1132 +1,1135 @@
/*
                This file is part of the Opie Project
=. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
/* OPIE */
#include <opie2/odebug.h>
#include <opie2/oversatileview.h>
#include <opie2/oversatileviewitem.h>
#include <opie2/olistview.h>
/* QT */
#include <qaction.h>
#include <qpopupmenu.h>
+using namespace Opie::Core;
+using namespace Opie::Ui;
+
/* XPM */
static const char * view_icon_xpm[] = {
"16 16 16 1",
" c None",
". c #87BD88",
"+ c #8BBE8B",
"@ c #81BA81",
"# c #6DAF6D",
"$ c #87BD87",
"% c #FCFDFC",
"& c #AED0AE",
"* c #4E9C4C",
"= c #91BD91",
"- c #72B172",
"; c #448643",
"> c #519F50",
", c #499247",
"' c #356A35",
") c #686868",
" ",
" .+@# .+@# ",
" $%&* $%&* ",
" @=-; @=-; ",
" #>,' #>,' ",
" ",
" )))))) )))))) ",
" ",
" ",
" .+@# .+@# ",
" $%&* $%&* ",
" @=-; @=-; ",
" #>,' #>,' ",
" ",
" )))))) )))))) ",
" "};
/* XPM */
static const char * view_tree_xpm[] = {
"16 16 17 1",
" c None",
". c #3A3A3A",
"+ c #87BD88",
"@ c #8BBE8B",
"# c #81BA81",
"$ c #6DAF6D",
"% c #87BD87",
"& c #FCFDFC",
"* c #AED0AE",
"= c #4E9C4C",
"- c #91BD91",
"; c #72B172",
"> c #448643",
", c #686868",
"' c #519F50",
") c #499247",
"! c #356A35",
" . ",
" . ",
" . +@#$ ",
" . %&*= ",
" .. #-;> ,, ,,,",
" . $')! ",
" . ",
" . ",
" . ",
" . +@#$ ",
" . %&*= ",
" .. #-;> ,, ,,,",
" $')! ",
" ",
" ",
" "};
OVersatileView::OVersatileView( QWidget* parent, const char* name, int mode )
:QWidgetStack( parent, name ),
_viewmode( mode ), _warningpolicy( None ),
_treeleaf(), _treeopened(), _treeclosed(),
_iconleaf(), _iconopened(), _iconclosed()
{
//
// Create child widgets and set some reasonable default styles
//
_listview = new OListView( this, "oversatileview embedded listview" );
_iconview = new QIconView( this, "oversatileview embedded iconview" );
_listview->setAllColumnsShowFocus( true );
_listview->setRootIsDecorated( true );
_listview->setShowSortIndicator( true );
_iconview->setGridX( 90 );
_iconview->setGridY( 42 );
_iconview->setAutoArrange( true );
-
+
#ifdef QWS // TODO: Let this depend on current geometry (rotation)
_iconview->setArrangement( QIconView::TopToBottom );
#else
_iconview->setArrangement( QIconView::LeftToRight );
#endif
-
+
_iconview->setResizeMode( QIconView::Adjust );
-
+
// qt-embedded: map stylus right on hold to right button press
#ifdef QWS
( (QPEApplication*) qApp)->setStylusOperation( _iconview->viewport(), QPEApplication::RightOnHold );
( (QPEApplication*) qApp)->setStylusOperation( _listview->viewport(), QPEApplication::RightOnHold );
#endif
setViewMode( mode ); // TODO: Read last style from config
// setSynchronization( true ); // TODO: Implement this
// create context menu allowing to switch between the views
_contextmenu = new QPopupMenu( 0, "oversatileview contextmenu" );
_contextmenu->setCaption( "Style" );
_contextmenu->setCheckable( true );
QActionGroup* ag = new QActionGroup( _contextmenu, "style option group" );
QAction* a1 = new QAction( "View Items in Icon Style", QIconSet( QPixmap( view_icon_xpm ) ),
"View Icons", 0, ag, "viewicon action", true );
QAction* a2 = new QAction( "View Items in Tree Style", QIconSet( QPixmap( view_tree_xpm ) ),
"View Tree", 0, ag, "viewtree action", true );
ag->addTo( _contextmenu );
if ( mode == Icons )
a1->setOn( true );
else if ( mode == Tree )
a2->setOn( true );
connect( a1, SIGNAL( activated() ), this, SLOT( setIconViewMode() ) );
connect( a2, SIGNAL( activated() ), this, SLOT( setTreeViewMode() ) );
-
+
#if (QT_VERSION >= 0x030000)
connect( _listview, SIGNAL( contextMenuRequested(QListViewItem*,const QPoint&,int) ), this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) );
connect( _iconview, SIGNAL( contextMenuRequested(QIconViewItem*,const QPoint&) ), this, SLOT( contextMenuRequested(QIconViewItem*,const QPoint&) ) );
#else
connect( _listview, SIGNAL( rightButtonPressed(QListViewItem*,const QPoint&,int) ), this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) );
connect( _iconview, SIGNAL( rightButtonPressed(QIconViewItem*,const QPoint&) ), this, SLOT( contextMenuRequested(QIconViewItem*,const QPoint&) ) );
#endif
-
+
//
// signal forwarders
//
// unfortunately we can't short-circuit all the QListView and QIconView signals
// to OVersatileView signals, because the signal/slot mechanism doesn't allow
// type-conversion :-(
// common signals for listview
-
+
connect( _listview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
connect( _listview, SIGNAL( selectionChanged(QListViewItem*) ), this, SLOT( selectionChanged(QListViewItem*) ) );
- connect( _listview, SIGNAL( currentChanged(QListViewItem*) ), this, SLOT( currentChanged(QListViewItem*) ) );
+ connect( _listview, SIGNAL( currentChanged(QListViewItem*) ), this, SLOT( currentChanged(QListViewItem*) ) );
connect( _listview, SIGNAL( clicked(QListViewItem*) ), this, SLOT( clicked(QListViewItem*) ) );
connect( _listview, SIGNAL( pressed(QListViewItem*) ), this, SLOT( pressed(QListViewItem*) ) );
-
+
connect( _listview, SIGNAL( doubleClicked(QListViewItem*) ), this, SLOT( doubleClicked(QListViewItem*) ) );
connect( _listview, SIGNAL( returnPressed(QListViewItem*) ), this, SLOT( returnPressed(QListViewItem*) ) );
-
+
connect( _listview, SIGNAL( onItem(QListViewItem*) ), this, SLOT( onItem(QListViewItem*) ) );
connect( _listview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) );
// common signals for iconview
-
+
connect( _iconview, SIGNAL( selectionChanged() ), this, SIGNAL( selectionChanged() ) );
connect( _iconview, SIGNAL( selectionChanged(QIconViewItem*) ), this, SLOT( selectionChanged(QIconViewItem*) ) );
- connect( _iconview, SIGNAL( currentChanged(QIconViewItem*) ), this, SLOT( currentChanged(QIconViewItem*) ) );
+ connect( _iconview, SIGNAL( currentChanged(QIconViewItem*) ), this, SLOT( currentChanged(QIconViewItem*) ) );
connect( _iconview, SIGNAL( clicked(QIconViewItem*) ), this, SLOT( clicked(QIconViewItem*) ) );
connect( _iconview, SIGNAL( pressed(QIconViewItem*) ), this, SLOT( pressed(QIconViewItem*) ) );
-
+
connect( _iconview, SIGNAL( doubleClicked(QIconViewItem*) ), this, SLOT( doubleClicked(QIconViewItem*) ) );
connect( _iconview, SIGNAL( returnPressed(QIconViewItem*) ), this, SLOT( returnPressed(QIconViewItem*) ) );
-
+
connect( _iconview, SIGNAL( onItem(QIconViewItem*) ), this, SLOT( onItem(QIconViewItem*) ) );
connect( _iconview, SIGNAL( onViewport() ), this, SIGNAL( onViewport() ) );
-
+
// listview only signals
-
+
connect( _listview, SIGNAL( expanded(QListViewItem*) ), this, SLOT( expanded(QListViewItem*) ) );
connect( _listview, SIGNAL( collapsed(QListViewItem*) ), this, SLOT( collapsed(QListViewItem*) ) );
-
+
// iconview only signals
-
+
connect( _iconview, SIGNAL( moved() ), this, SIGNAL( moved() ) );
}
OVersatileView::~OVersatileView()
{
}
QPopupMenu* OVersatileView::contextMenu() const
{
return _contextmenu;
}
void OVersatileView::contextMenuRequested( QListViewItem* item, const QPoint& pos, int col )
{
// can't use QObject::inherits here, because ListViewItems, beit Q, O or K,
// do not inherit from QObject - assuming here the programmer is
// disciplined enough to only add OVersatileViewItems to an OVersatileView
popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, col );
}
void OVersatileView::contextMenuRequested( QIconViewItem* item, const QPoint& pos )
{
// see above
popupContextMenu( static_cast<OVersatileViewItem*>( item ), pos, -1 );
}
void OVersatileView::popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col )
{
if ( !item )
_contextmenu->exec( pos );
else
emit( contextMenuRequested( item, pos, col ) );
}
void OVersatileView::setSynchronization( bool sync )
{
_synchronization = sync;
}
bool OVersatileView::synchronization()
{
return _synchronization;
}
void OVersatileView::setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed )
{
if ( mode == Tree )
{
_treeleaf = leaf;
_treeopened = opened;
_treeclosed = closed;
}
else if ( mode == Icons )
{
_iconleaf = leaf;
_iconopened = opened;
_iconclosed = closed;
}
else
{
odebug << "OVersatileView::setDefaultPixmaps(): invalid mode" << oendl;
}
}
QIconView* OVersatileView::iconView() const
{
return _iconview;
}
OListView* OVersatileView::listView() const
{
return _listview;
}
void OVersatileView::setViewMode( int mode )
{
if ( mode == Tree )
{
_viewmode = mode;
raiseWidget( _listview );
}
else if ( mode == Icons )
{
_viewmode = mode;
raiseWidget( _iconview );
}
else
{
odebug << "OVersatileView::setViewMode(): invalid mode" << oendl;
}
}
void OVersatileView::setIconViewMode()
{
setViewMode( Icons );
}
void OVersatileView::setTreeViewMode()
{
setViewMode( Tree );
}
bool OVersatileView::isValidViewMode( int mode ) const
{
switch ( _warningpolicy )
{
case OVersatileView::None:
{
return true;
}
case OVersatileView::Warn:
{
if ( _viewmode != mode )
{
odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl;
return true;
}
}
case OVersatileView::WarnReturn:
{
if ( _viewmode != mode )
{
odebug << "OVersatileView::isValidViewMode(): Requested operation not valid in current mode." << oendl;
return false;
}
}
default:
{
owarn << "OVersatileView::isValidViewMode(): Inconsistent object state!" << oendl;
return true;
}
}
}
void OVersatileView::setWarningPolicy( int policy ) const
{
_warningpolicy = policy;
}
bool OVersatileView::warningPolicy() const
{
return _warningpolicy;
}
//==============================================================================================//
// Stupid Signal forwarders...
// Folks, this is why I like python with its dynamic typing:
// I can code the following dozens of lines C++ in four Python lines...
//==============================================================================================//
void OVersatileView::selectionChanged( QListViewItem * item )
{
emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::selectionChanged( QIconViewItem * item )
{
emit( selectionChanged( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::currentChanged( QListViewItem * item )
{
emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::currentChanged( QIconViewItem * item )
{
emit( currentChanged( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::clicked( QListViewItem * item )
{
emit( clicked( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::clicked( QIconViewItem * item )
{
emit( clicked( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::pressed( QListViewItem * item )
{
emit( pressed( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::pressed( QIconViewItem * item )
{
emit( pressed( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::doubleClicked( QListViewItem * item )
{
emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::doubleClicked( QIconViewItem * item )
{
emit( doubleClicked( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::returnPressed( QListViewItem * item )
{
emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) );
}
-
+
void OVersatileView::returnPressed( QIconViewItem * item )
{
emit( returnPressed( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::onItem( QListViewItem * item )
{
emit( onItem( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::onItem( QIconViewItem * item )
{
emit( onItem( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::expanded( QListViewItem *item ) // QListView
{
//odebug << "OVersatileView::expanded(): opening tree..." << oendl;
if ( !_treeopened.isNull() )
item->setPixmap( 0, _treeopened );
emit( expanded( static_cast<OVersatileViewItem*>( item ) ) );
}
void OVersatileView::collapsed( QListViewItem *item ) // QListView
{
if ( !_treeclosed.isNull() )
item->setPixmap( 0, _treeclosed );
emit( collapsed( static_cast<OVersatileViewItem*>( item ) ) );
}
//=============================================================================================//
// OVersatileView Case I - API only existing in QListView or QIconView but not in both!
//==============================================================================================//
-
+
int OVersatileView::treeStepSize() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->treeStepSize();
}
void OVersatileView::setTreeStepSize( int size ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setTreeStepSize( size );
}
QHeader * OVersatileView::header() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return 0;
}
return _listview->header();
}
int OVersatileView::addColumn( const QString &label, int size ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->addColumn( label, size );
}
int OVersatileView::addColumn( const QIconSet& iconset, const QString &label, int size ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->addColumn( iconset, label, size );
}
void OVersatileView::removeColumn( int index ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->removeColumn( index );
}
void OVersatileView::setColumnText( int column, const QString &label ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setColumnText( column, label );
}
void OVersatileView::setColumnText( int column, const QIconSet& iconset, const QString &label ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setColumnText( column, iconset, label );
}
QString OVersatileView::columnText( int column ) const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return QString::null;
}
return _listview->columnText( column );
}
void OVersatileView::setColumnWidth( int column, int width ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setColumnWidth( column, width );
}
int OVersatileView::columnWidth( int column ) const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->columnWidth( column );
}
void OVersatileView::setColumnWidthMode( int column, WidthMode mode ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setColumnWidth( column, mode );
}
int OVersatileView::columns() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->columns();
}
void OVersatileView::setColumnAlignment( int column, int align ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setColumnAlignment( column, align );
}
int OVersatileView::columnAlignment( int column ) const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->columnAlignment( column );
}
OVersatileViewItem * OVersatileView::itemAt( const QPoint & screenPos ) const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _listview->itemAt( screenPos ) );
}
QRect OVersatileView::itemRect( const OVersatileViewItem * item ) const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return QRect( -1, -1, -1, -1 );
}
return _listview->itemRect( item );
}
int OVersatileView::itemPos( const OVersatileViewItem * item ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->itemPos( item );
}
bool OVersatileView::isSelected( const OVersatileViewItem * item ) const // QListView // also in QIconViewItem but !in QIconView *shrug*
{
if ( !isValidViewMode( Tree ) )
{
return false;
}
return _listview->isSelected( item );
}
void OVersatileView::setMultiSelection( bool enable )
{
_listview->setMultiSelection( enable );
}
bool OVersatileView::isMultiSelection() const
{
return _listview->isMultiSelection();
}
OVersatileViewItem * OVersatileView::selectedItem() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _listview->selectedItem() );
}
void OVersatileView::setOpen( OVersatileViewItem * item, bool open ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setOpen( item, open );
}
bool OVersatileView::isOpen( const OVersatileViewItem * item ) const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return false;
}
return _listview->isOpen( item );
}
OVersatileViewItem * OVersatileView::firstChild() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _listview->firstChild() );
}
int OVersatileView::childCount() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->childCount();
}
void OVersatileView::setAllColumnsShowFocus( bool focus ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setAllColumnsShowFocus( focus );
}
bool OVersatileView::allColumnsShowFocus() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return false;
}
return _listview->allColumnsShowFocus();
}
void OVersatileView::setItemMargin( int margin ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setItemMargin( margin );
}
int OVersatileView::itemMargin() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return -1;
}
return _listview->itemMargin();
}
void OVersatileView::setRootIsDecorated( bool decorate ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setRootIsDecorated( decorate );
}
bool OVersatileView::rootIsDecorated() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return false;
}
return _listview->rootIsDecorated();
}
void OVersatileView::setShowSortIndicator( bool show ) // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->setShowSortIndicator( show );
}
bool OVersatileView::showSortIndicator() const // QListView
{
if ( !isValidViewMode( Tree ) )
{
return false;
}
return _listview->showSortIndicator();
}
void OVersatileView::triggerUpdate() // QListView
{
if ( !isValidViewMode( Tree ) )
{
return;
}
_listview->triggerUpdate();
}
//
// only in QIconView
//
-
+
uint OVersatileView::count() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return 0;
}
return _iconview->count();
}
int OVersatileView::index( const OVersatileViewItem *item ) const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return -1;
}
return _iconview->index( item );
}
OVersatileViewItem* OVersatileView::firstItem() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _iconview->firstItem() );
}
OVersatileViewItem* OVersatileView::lastItem() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _iconview->lastItem() );
}
OVersatileViewItem* OVersatileView::findItem( const QPoint &pos ) const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _iconview->findItem( pos ) );
}
OVersatileViewItem* OVersatileView::findItem( const QString &text ) const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _iconview->findItem( text ) );
}
OVersatileViewItem* OVersatileView::findFirstVisibleItem( const QRect &r ) const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _iconview->findFirstVisibleItem( r ) );
}
OVersatileViewItem* OVersatileView::findLastVisibleItem( const QRect &r ) const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return 0;
}
return static_cast<OVersatileViewItem*>( _iconview->findLastVisibleItem( r ) );
}
void OVersatileView::setGridX( int rx ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setGridX( rx );
}
void OVersatileView::setGridY( int ry ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setGridY( ry );
}
int OVersatileView::gridX() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return -1;
}
return _iconview->gridX();
}
int OVersatileView::gridY() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return -1;
}
return _iconview->gridY();
}
void OVersatileView::setSpacing( int sp ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setSpacing( sp );
}
int OVersatileView::spacing() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return -1;
}
return _iconview->spacing();
}
void OVersatileView::setItemTextPos( QIconView::ItemTextPos pos ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setItemTextPos( pos );
}
QIconView::ItemTextPos OVersatileView::itemTextPos() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return (QIconView::ItemTextPos) -1;
}
return _iconview->itemTextPos();
}
void OVersatileView::setItemTextBackground( const QBrush &b ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setItemTextBackground( b );
}
QBrush OVersatileView::itemTextBackground() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return QBrush();
}
return _iconview->itemTextBackground();
}
void OVersatileView::setArrangement( QIconView::Arrangement am ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setArrangement( am );
}
QIconView::Arrangement OVersatileView::arrangement() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return (QIconView::Arrangement) -1;
}
return _iconview->arrangement();
}
void OVersatileView::setResizeMode( QIconView::ResizeMode am ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setResizeMode( am );
}
QIconView::ResizeMode OVersatileView::resizeMode() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return (QIconView::ResizeMode) -1;
}
return _iconview->resizeMode();
}
void OVersatileView::setMaxItemWidth( int w ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setMaxItemWidth( w );
}
int OVersatileView::maxItemWidth() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return -1;
}
return _iconview->maxItemWidth();
}
void OVersatileView::setMaxItemTextLength( int w ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setMaxItemTextLength( w );
}
int OVersatileView::maxItemTextLength() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return -1;
}
return _iconview->maxItemTextLength();
}
void OVersatileView::setAutoArrange( bool b ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setAutoArrange( b );
}
bool OVersatileView::autoArrange() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return false;
}
return _iconview->autoArrange();
}
void OVersatileView::setShowToolTips( bool b ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setShowToolTips( b );
}
bool OVersatileView::showToolTips() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return false;
}
return _iconview->showToolTips();
}
bool OVersatileView::sorting() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return false;
}
return _iconview->sorting();
}
bool OVersatileView::sortDirection() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return false;
}
return _iconview->sortDirection();
}
void OVersatileView::setItemsMovable( bool b ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setItemsMovable( b );
}
bool OVersatileView::itemsMovable() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return false;
}
return _iconview->itemsMovable();
}
void OVersatileView::setWordWrapIconText( bool b ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->setWordWrapIconText( b );
}
bool OVersatileView::wordWrapIconText() const // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return false;
}
return _iconview->wordWrapIconText();
}
void OVersatileView::arrangeItemsInGrid( const QSize &grid, bool update ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->arrangeItemsInGrid( grid, update );
}
void OVersatileView::arrangeItemsInGrid( bool update ) // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->arrangeItemsInGrid( update );
}
void OVersatileView::updateContents() // QIconView
{
if ( !isValidViewMode( Icons ) )
{
return;
}
_iconview->updateContents();
}
//==============================================================================================//
// OVersatileView Case II - QListView / QIconView common API
//==============================================================================================//
void OVersatileView::clear()
{
_iconview->clear();
_listview->clear();
}
void OVersatileView::setFont( const QFont & font )
{
_iconview->setFont( font );
_listview->setFont( font );
}
void OVersatileView::setPalette( const QPalette & palette )
{
_iconview->setPalette( palette );
_listview->setPalette( palette );
}
void OVersatileView::takeItem( OVersatileViewItem * item )
{
_iconview->takeItem( item );
_listview->takeItem( item );
}
void OVersatileView::setSelectionMode( SelectionMode mode )
{
_iconview->setSelectionMode( (QIconView::SelectionMode) mode );
_listview->setSelectionMode( (QListView::SelectionMode) mode );
}
OVersatileView::SelectionMode OVersatileView::selectionMode() const
{
return (OVersatileView::SelectionMode) _iconview->selectionMode();
}
void OVersatileView::selectAll( bool select )
{
_iconview->selectAll( select );
}
void OVersatileView::clearSelection()
{
_iconview->clearSelection();
_listview->clearSelection();
}
void OVersatileView::invertSelection()
{
_iconview->invertSelection();
_listview->invertSelection();
}
void OVersatileView::ensureItemVisible( const OVersatileViewItem * item )
{
_iconview->ensureItemVisible( const_cast<OVersatileViewItem*>( item ) );
_listview->ensureItemVisible( item );
}
void OVersatileView::repaintItem( const OVersatileViewItem * item ) const
{
_iconview->repaintItem( const_cast<OVersatileViewItem*>( item ) );
_listview->repaintItem( item );
}
diff --git a/libopie2/opieui/oversatileview.h b/libopie2/opieui/oversatileview.h
index 8af21dc..61b61db 100644
--- a/libopie2/opieui/oversatileview.h
+++ b/libopie2/opieui/oversatileview.h
@@ -1,394 +1,399 @@
/*
                This file is part of the Opie Project
=. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OVERSATILEVIEW_H
#define OVERSATILEVIEW_H
/* QT */
#include <qwidgetstack.h>
#include <qiconview.h>
/* OPIE */
#include <opie2/oapplication.h>
/* FORWARDS */
class QHeader;
class QIconSet;
class QIconViewItem;
-class OListView;
class QListViewItem;
class QPopupMenu;
class QString;
#ifndef QT_NO_DRAGANDDROP
class QIconDragItem;
#endif
+namespace Opie {
+namespace Ui {
+class OListView;
+
class OVersatileView : public QWidgetStack
{
Q_OBJECT
-
+
friend class OVersatileViewItem;
//==============================================================================================//
// OVersatileView High Level API
//==============================================================================================//
public:
OVersatileView( QWidget* parent = 0, const char* name = 0, int mode = 0 );
~OVersatileView();
QPopupMenu* contextMenu() const;
-
+
void setSynchronization( bool sync );
bool synchronization();
-
+
enum ViewMode { Tree = 0, Icons };
int viewMode();
-
+
QIconView* iconView() const;
OListView* listView() const;
-
+
enum WarningPolicy { None = 0, Warn, WarnReturn };
-
+
void setWarningPolicy( int ) const; // warn, if calling a method which doesn't apply to the current viewmode
bool warningPolicy() const;
-
+
void setDefaultPixmaps( int mode, QPixmap& leaf, QPixmap& opened, QPixmap& closed );
-
+
public slots:
void setViewMode( int mode );
void setIconViewMode();
void setTreeViewMode();
protected:
virtual bool isValidViewMode( int mode ) const;
virtual void popupContextMenu( OVersatileViewItem* item, const QPoint& pos, int col = 0 );
-
+
private:
int _viewmode;
bool _synchronization;
mutable int _warningpolicy;
-
+
OListView* _listview;
QIconView* _iconview;
-
+
QPixmap _treeleaf;
QPixmap _treeopened;
QPixmap _treeclosed;
QPixmap _iconleaf;
QPixmap _iconopened;
QPixmap _iconclosed;
-
+
QPopupMenu* _contextmenu;
-
+
int _iconstyle;
int _treestyle;
-
+
private slots:
-
+
void contextMenuRequested( QListViewItem*, const QPoint&, int );
void contextMenuRequested( QIconViewItem*, const QPoint& );
// type converting signal forwarders
-
+
void selectionChanged( QListViewItem * );
void currentChanged( QListViewItem * );
void clicked( QListViewItem * );
void pressed( QListViewItem * );
void doubleClicked( QListViewItem * );
void returnPressed( QListViewItem * );
void onItem( QListViewItem * );
-
+
void selectionChanged( QIconViewItem * );
void currentChanged( QIconViewItem * );
void clicked( QIconViewItem * );
void pressed( QIconViewItem * );
void doubleClicked( QIconViewItem * );
void returnPressed( QIconViewItem * );
void onItem( QIconViewItem * );
-
+
void expanded( QListViewItem * item ); // QListView
void collapsed( QListViewItem * item ); // QListView
signals:
-
+
void contextMenuRequested( OVersatileViewItem * item, const QPoint& pos, int col );
-
+
/*#ifndef QT_NO_DRAGANDDROP
void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); // QIconView
#endif
void itemRenamed( OVersatileViewItem *item, const QString & ); // QIconView
void itemRenamed( OVersatileViewItem *item ); // QIconView
*/
//==============================================================================================//
// "Derived" API - Case 1: Methods existing either only in QListView or only in QIconView
//==============================================================================================//
public:
/*
enum Arrangement { // QIconView
LeftToRight = 0,
TopToBottom
};
enum ResizeMode { // QIconView
Fixed = 0,
Adjust
};
enum ItemTextPos { // QIconView
Bottom = 0,
Right
};
*/
-
+
//
// only in QListView
//
-
+
int treeStepSize() const; // QListView
virtual void setTreeStepSize( int ); // QListView
QHeader * header() const; // QListView
virtual int addColumn( const QString &label, int size = -1); // QListView
virtual int addColumn( const QIconSet& iconset, const QString &label, int size = -1); // QListView
void removeColumn( int index ); // #### make virtual in next major release! // QListView
virtual void setColumnText( int column, const QString &label ); // QListView
virtual void setColumnText( int column, const QIconSet& iconset, const QString &label ); // QListView
QString columnText( int column ) const; // QListView
virtual void setColumnWidth( int column, int width ); // QListView
int columnWidth( int column ) const; // QListView
enum WidthMode { Manual, Maximum }; // QListView
virtual void setColumnWidthMode( int column, WidthMode ); // QListView
WidthMode columnWidthMode( int column ) const; // QListView
int columns() const; // QListView
virtual void setColumnAlignment( int, int ); // QListView
int columnAlignment( int ) const; // QListView
OVersatileViewItem * itemAt( const QPoint & screenPos ) const; // QListView
QRect itemRect( const OVersatileViewItem * ) const; // QListView
int itemPos( const OVersatileViewItem * ); // QListView
bool isSelected( const OVersatileViewItem * ) const; // QListView // also in QIconViewItem but not in QIconView *shrug*
virtual void setMultiSelection( bool enable ); // QListView
bool isMultiSelection() const; // QListView
OVersatileViewItem * selectedItem() const; // QListView
virtual void setOpen( OVersatileViewItem *, bool ); // QListView
bool isOpen( const OVersatileViewItem * ) const; // QListView
OVersatileViewItem * firstChild() const; // QListView
int childCount() const; // QListView
virtual void setAllColumnsShowFocus( bool ); // QListView
bool allColumnsShowFocus() const; // QListView
virtual void setItemMargin( int ); // QListView
int itemMargin() const; // QListView
virtual void setRootIsDecorated( bool ); // QListView
bool rootIsDecorated() const; // QListView
void setShowSortIndicator( bool show ); // QListView
bool showSortIndicator() const; // QListView
-
+
int index( const OVersatileViewItem *item ) const; // QIconView
public slots:
void triggerUpdate(); // QListView
signals:
void expanded( OVersatileViewItem *item ); // QListView
void collapsed( OVersatileViewItem *item ); // QListView
//
// only in QIconView
//
- public:
+ public:
uint count() const; // QIconView
-
+
OVersatileViewItem *firstItem() const; // QIconView
OVersatileViewItem *lastItem() const; // QIconView
OVersatileViewItem *findItem( const QPoint &pos ) const; // QIconView
OVersatileViewItem *findItem( const QString &text ) const; // QIconView
OVersatileViewItem* findFirstVisibleItem( const QRect &r ) const; // QIconView
OVersatileViewItem* findLastVisibleItem( const QRect &r ) const; // QIconView
virtual void setGridX( int rx ); // QIconView
virtual void setGridY( int ry ); // QIconView
int gridX() const; // QIconView
int gridY() const; // QIconView
virtual void setSpacing( int sp ); // QIconView
int spacing() const; // QIconView
virtual void setItemTextPos( QIconView::ItemTextPos pos ); // QIconView
QIconView::ItemTextPos itemTextPos() const; // QIconView
virtual void setItemTextBackground( const QBrush &b ); // QIconView
QBrush itemTextBackground() const; // QIconView
virtual void setArrangement( QIconView::Arrangement am ); // QIconView
QIconView::Arrangement arrangement() const; // QIconView
virtual void setResizeMode( QIconView::ResizeMode am ); // QIconView
QIconView::ResizeMode resizeMode() const; // QIconView
virtual void setMaxItemWidth( int w ); // QIconView
int maxItemWidth() const; // QIconView
virtual void setMaxItemTextLength( int w ); // QIconView
int maxItemTextLength() const; // QIconView
virtual void setAutoArrange( bool b ); // QIconView
bool autoArrange() const; // QIconView
virtual void setShowToolTips( bool b ); // QIconView
bool showToolTips() const; // QIconView
bool sorting() const; // QIconView
bool sortDirection() const; // QIconView
virtual void setItemsMovable( bool b ); // QIconView
bool itemsMovable() const; // QIconView
virtual void setWordWrapIconText( bool b ); // QIconView
bool wordWrapIconText() const; // QIconView
public slots:
virtual void arrangeItemsInGrid( const QSize &grid, bool update = TRUE ); // QIconView
virtual void arrangeItemsInGrid( bool update = TRUE ); // QIconView
virtual void updateContents(); // QIconView
-
+
signals:
/*#ifndef QT_NO_DRAGANDDROP
void dropped( QDropEvent *e, const QValueList<QIconDragItem> &lst ); // QIconView
#endif
*/
void moved(); // QIconView
void itemRenamed( OVersatileViewItem *item, const QString & ); // QIconView
void itemRenamed( OVersatileViewItem *item ); // QIconView
//==============================================================================================//
// "Derived" API - Case 2: Methods existing in QListView and QIconView with the same signatures
//==============================================================================================//
public:
enum SelectionMode {
Single = 0,
Multi,
Extended,
NoSelection
};
virtual void clear();
virtual void setFont( const QFont & );
virtual void setPalette( const QPalette & );
virtual void takeItem( OVersatileViewItem * );
void setSelectionMode( SelectionMode mode );
SelectionMode selectionMode() const;
virtual void selectAll( bool select );
virtual void clearSelection();
virtual void invertSelection();
-
+
void ensureItemVisible( const OVersatileViewItem * );
virtual void repaintItem( const OVersatileViewItem * ) const;
virtual void setCurrentItem( OVersatileViewItem * );
OVersatileViewItem * currentItem() const;
// bool eventFilter( QObject * o, QEvent * ); // use QWidgetStack implementation
// QSize minimumSizeHint() const; // use QWidgetStack implementation
// QSizePolicy sizePolicy() const; // use QWidgetStack implementation
// QSize sizeHint() const; // use QWidgetStack implementation
signals:
void selectionChanged();
void selectionChanged( OVersatileViewItem * );
void currentChanged( OVersatileViewItem * );
void clicked( OVersatileViewItem * );
void pressed( OVersatileViewItem * );
void doubleClicked( OVersatileViewItem * );
void returnPressed( OVersatileViewItem * );
-
+
void onItem( OVersatileViewItem * );
void onViewport();
-
+
//==============================================================================================//
// "Derived" API - Case 2: Methods existing in QListView and QIconView with differing signatures
//==============================================================================================//
-
+
/*
-
+
public:
virtual void insertItem( OVersatileViewItem * ); // QListView
virtual void insertItem( OVersatileViewItem *item, OVersatileViewItem *after = 0L ); // QIconView
virtual void setSelected( OVersatileViewItem *, bool ); // QListView
virtual void setSelected( OVersatileViewItem *item, bool s, bool cb = FALSE ); // QIconView
virtual void setSorting( int column, bool increasing = TRUE ); // QListView
void setSorting( bool sort, bool ascending = TRUE ); // QIconView
void sort(); // #### make virtual in next major release // QListView
virtual void sort( bool ascending = TRUE ); // QIconView
*/
-
+
signals:
void clicked( OVersatileViewItem *, const QPoint &, int ); // QListView
void clicked( OVersatileViewItem *, const QPoint & ); // QIconView
-
+
void pressed( OVersatileViewItem *, const QPoint &, int ); // QListView
void pressed( OVersatileViewItem *, const QPoint & ); // QIconView
-
+
void rightButtonClicked( OVersatileViewItem* item, const QPoint& pos ); // QIconView
void rightButtonClicked( OVersatileViewItem *, const QPoint&, int ); // QListView
-
- void rightButtonPressed( OVersatileViewItem* item, const QPoint& pos ); // QIconView
+
+ void rightButtonPressed( OVersatileViewItem* item, const QPoint& pos ); // QIconView
void rightButtonPressed( OVersatileViewItem *, const QPoint&, int ); // QListView
-
+
void mouseButtonPressed( int, OVersatileViewItem *, const QPoint& , int ); // QListView
void mouseButtonPressed( int button, OVersatileViewItem* item, const QPoint& pos ); // QIconView
-
+
void mouseButtonClicked( int, OVersatileViewItem *, const QPoint&, int ); // QListView
void mouseButtonClicked( int button, OVersatileViewItem* item, const QPoint& pos ); // QIconView
};
+}
+}
#endif
diff --git a/libopie2/opieui/oversatileviewitem.cpp b/libopie2/opieui/oversatileviewitem.cpp
index 66de8eb..03c6738 100644
--- a/libopie2/opieui/oversatileviewitem.cpp
+++ b/libopie2/opieui/oversatileviewitem.cpp
@@ -1,132 +1,134 @@
/*
                This file is part of the Opie Project
=. (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/oversatileviewitem.h>
#include <opie2/oversatileview.h>
+using namespace Opie::Ui;
+
OVersatileViewItem::OVersatileViewItem( OVersatileView * parent )
:OListViewItem( parent->_listview ), QIconViewItem( parent->_iconview ),
_versatileview( parent )
{
init();
}
OVersatileViewItem::OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after )
:OListViewItem( parent->_listview, after ), QIconViewItem( parent->_iconview, after ),
_versatileview( parent )
{
init();
}
OVersatileViewItem::OVersatileViewItem( OVersatileView * parent,
QString a, QString b, QString c, QString d,
QString e, QString f, QString g, QString h )
:OListViewItem( parent->_listview, a, b, c, d, e, f, g, h ),
QIconViewItem( parent->_iconview, a ),
_versatileview( parent )
{
init();
}
OVersatileViewItem::OVersatileViewItem( OVersatileView * parent, OVersatileViewItem* after,
QString a, QString b, QString c, QString d,
QString e, QString f, QString g, QString h )
:OListViewItem( parent->_listview, after, a, b, c, d, e, f, g, h ),
QIconViewItem( parent->_iconview, after, a ),
_versatileview( parent )
{
init();
}
OVersatileViewItem::OVersatileViewItem( OVersatileViewItem * parent,
QString a, QString b, QString c, QString d,
QString e, QString f, QString g, QString h )
:OListViewItem( parent, a, b, c, d, e, f, g, h ),
QIconViewItem( parent->_versatileview->_iconview, a ),
_versatileview( parent->_versatileview )
{
init();
}
OVersatileViewItem::OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem* after,
QString a, QString b, QString c, QString d,
QString e, QString f, QString g, QString h )
:OListViewItem( parent, after, a, b, c, d, e, f, g, h ),
QIconViewItem( parent->_versatileview->_iconview, after, a ),
_versatileview( parent->_versatileview )
{
init();
}
OVersatileViewItem::~OVersatileViewItem()
{
}
OVersatileView* OVersatileViewItem::versatileView() const
{
return _versatileview;
}
void OVersatileViewItem::init()
{
if ( !firstChild() )
{
// I'm a sweet yellow and browne autumn leaf
OListViewItem::setPixmap( 0, _versatileview->_treeleaf );
QIconViewItem::setPixmap( _versatileview->_iconleaf );
}
else
{
// I'm a node and I have a little baby child
if ( isOpen() )
{
OListViewItem::setPixmap( 0, _versatileview->_treeopened );
QIconViewItem::setPixmap( _versatileview->_iconopened );
}
else
{
OListViewItem::setPixmap( 0, _versatileview->_treeclosed );
QIconViewItem::setPixmap( _versatileview->_iconclosed );
}
}
}
void OVersatileViewItem::setRenameEnabled( bool allow )
{
#if (QT_VERSION >= 0x030000)
OListViewItem::setRenameEnabled( 0, allow ); // TODO: Backport to Qt-Embedded 2.x?
#endif
QIconViewItem::setRenameEnabled( allow );
}
diff --git a/libopie2/opieui/oversatileviewitem.h b/libopie2/opieui/oversatileviewitem.h
index ee8ee20..c4977af 100644
--- a/libopie2/opieui/oversatileviewitem.h
+++ b/libopie2/opieui/oversatileviewitem.h
@@ -1,100 +1,105 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OVERSATILEVIEWITEM_H
#define OVERSATILEVIEWITEM_H
/* QT */
#include <qiconview.h>
/* OPIE */
#include <opie2/olistview.h>
+namespace Opie {
+namespace Ui {
+
class OVersatileView;
class OVersatileViewItem : public OListViewItem, public QIconViewItem
{
public:
OVersatileViewItem( OVersatileView * parent );
OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after );
OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem * after );
OVersatileViewItem( OVersatileView * parent, QString,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null );
OVersatileViewItem( OVersatileViewItem * parent, QString,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null );
OVersatileViewItem( OVersatileView * parent, OVersatileViewItem * after, QString,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null );
OVersatileViewItem( OVersatileViewItem * parent, OVersatileViewItem * after, QString,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null, QString = QString::null,
QString = QString::null );
virtual ~OVersatileViewItem();
OVersatileView* versatileView() const;
// TODO: Implement the remaining constructors from QIconView
/* OIconViewItem( QIconView *parent, const QString &text, const QPixmap &icon );
OIconViewItem( QIconView *parent, QIconViewItem *after, const QString &text, const QPixmap &icon );
*/
virtual void setRenameEnabled( bool );
// TODO: Implement the remaining method multiplexers
private:
OVersatileView* _versatileview;
private:
void init();
};
+}
+}
#endif
diff --git a/libopie2/opieui/owait.cpp b/libopie2/opieui/owait.cpp
index 8bb4ed6..9519888 100644
--- a/libopie2/opieui/owait.cpp
+++ b/libopie2/opieui/owait.cpp
@@ -1,110 +1,112 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "owait.h"
/* OPIE */
#include <qpe/qpeapplication.h>
#include <qpe/resource.h>
/* QT */
#include <qlayout.h>
#include <qpainter.h>
+using namespace Opie::Ui;
+
static int frame = 0;
/**
* This will construct a modal dialog.
*
* The default timer length is 10.
*
* @param parent The parent of the widget
* @param msg The name of the object
* @param dispIcon Display Icon?
*/
OWait::OWait( QWidget *parent, const char* msg, bool dispIcon )
:QDialog( parent, msg, TRUE, WStyle_Customize )
{
QHBoxLayout * hbox = new QHBoxLayout( this );
m_lb = new QLabel( this );
m_lb->setBackgroundMode ( NoBackground );
hbox->addWidget( m_lb );
hbox->activate();
m_pix = Resource::loadPixmap( "BigBusy" );
m_aniSize = m_pix.height();
resize( m_aniSize, m_aniSize );
m_timerLength = 10;
m_waitTimer = new QTimer( this );
connect( m_waitTimer, SIGNAL( timeout() ), this, SLOT( hide() ) );
}
void OWait::timerEvent( QTimerEvent * )
{
frame = ( ++frame ) % 4;
repaint();
}
void OWait::paintEvent( QPaintEvent * )
{
QPainter p( m_lb );
p.drawPixmap( 0, 0, m_pix, m_aniSize * frame, 0, m_aniSize, m_aniSize );
}
void OWait::show()
{
move( ( ( qApp->desktop() ->width() ) / 2 ) - ( m_aniSize / 2 ), ( ( qApp->desktop() ->height() ) / 2 ) - ( m_aniSize / 2 ) );
startTimer( 300 );
m_waitTimer->start( m_timerLength * 1000, true );
QDialog::show();
}
void OWait::hide()
{
killTimers();
m_waitTimer->stop();
frame = 0;
QDialog::hide();
}
void OWait::setTimerLength( int length )
{
m_timerLength = length;
}
OWait::~OWait()
{}
diff --git a/libopie2/opieui/owait.h b/libopie2/opieui/owait.h
index 3267064..03c33e4 100644
--- a/libopie2/opieui/owait.h
+++ b/libopie2/opieui/owait.h
@@ -1,86 +1,90 @@
/*
                This file is part of the Opie Project
              Copyright (C) 2003 Maximilian Reiss <harlekin@handhelds.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef OWAIT_H
#define OWAIT_H
/* QT */
#include <qdialog.h>
#include <qlabel.h>
#include <qpixmap.h>
#include <qtimer.h>
+
+namespace Opie {
+namespace Ui {
/**
* This class displays a animated waiting icon in the middle of the screen.
*
* @short modal hour glass dialog
* @see QDialog
* @author Maximilian Reiß
*/
class OWait : public QDialog
{
Q_OBJECT
public:
OWait( QWidget *parent = 0, const char* name = 0, bool dispIcon = TRUE );
~OWait();
/**
* reimplemented for control reasons
*/
void show();
/**
* Set the time before the icon will be automaticly hidden
* The timer will be started once the widget will be shown.
* @param length - time in seconds
*/
void setTimerLength( int length );
public slots:
/**
* reimplemented for control reasons
*/
void hide();
private:
void timerEvent( QTimerEvent * );
void paintEvent( QPaintEvent * );
QPixmap m_pix;
QLabel *m_lb;
QTimer *m_waitTimer;
int m_timerLength;
int m_aniSize;
class Private;
Private *d;
};
-
+}
+}
#endif