From e2de64d6f1beb9e492daf5b886e19933c1fa41dd Mon Sep 17 00:00:00 2001 From: toma Date: Wed, 25 Nov 2009 17:56:58 +0000 Subject: Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features. BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdemultimedia@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da --- arts/gui/kde/Makefile.am | 38 ++ arts/gui/kde/artstestgui.cpp | 124 +++++ arts/gui/kde/dbtest.cpp | 42 ++ arts/gui/kde/dbtest.h | 16 + arts/gui/kde/dbvolcalc.h | 82 +++ arts/gui/kde/kartswidget.cpp | 89 ++++ arts/gui/kde/kartswidget.h | 92 ++++ arts/gui/kde/kbutton_impl.cpp | 135 +++++ arts/gui/kde/kbutton_impl.h | 76 +++ arts/gui/kde/kcombobox_impl.cpp | 105 ++++ arts/gui/kde/kcombobox_impl.h | 74 +++ arts/gui/kde/kfader.cpp | 31 ++ arts/gui/kde/kfader.h | 46 ++ arts/gui/kde/kfader_impl.cpp | 206 ++++++++ arts/gui/kde/kfader_impl.h | 92 ++++ arts/gui/kde/kframe_impl.cpp | 98 ++++ arts/gui/kde/kframe_impl.h | 55 ++ arts/gui/kde/kgraph.cpp | 266 ++++++++++ arts/gui/kde/kgraph.h | 64 +++ arts/gui/kde/kgraph_impl.cpp | 92 ++++ arts/gui/kde/kgraph_impl.h | 65 +++ arts/gui/kde/kgraphline_impl.cpp | 124 +++++ arts/gui/kde/kgraphline_impl.h | 61 +++ arts/gui/kde/khbox_impl.cpp | 51 ++ arts/gui/kde/khbox_impl.h | 48 ++ arts/gui/kde/klabel_impl.cpp | 104 ++++ arts/gui/kde/klabel_impl.h | 90 ++++ arts/gui/kde/klayoutbox_impl.cpp | 122 +++++ arts/gui/kde/klayoutbox_impl.h | 103 ++++ arts/gui/kde/klevelmeter_firebars.cpp | 125 +++++ arts/gui/kde/klevelmeter_firebars.h | 58 +++ arts/gui/kde/klevelmeter_impl.cpp | 131 +++++ arts/gui/kde/klevelmeter_impl.h | 70 +++ arts/gui/kde/klevelmeter_linebars.cpp | 109 ++++ arts/gui/kde/klevelmeter_linebars.h | 46 ++ arts/gui/kde/klevelmeter_normalbars.cpp | 81 +++ arts/gui/kde/klevelmeter_normalbars.h | 75 +++ arts/gui/kde/klevelmeter_private.h | 55 ++ arts/gui/kde/klevelmeter_small.cpp | 59 +++ arts/gui/kde/klevelmeter_small.h | 39 ++ arts/gui/kde/klevelmeter_template.h | 70 +++ arts/gui/kde/klineedit_impl.cpp | 75 +++ arts/gui/kde/klineedit_impl.h | 63 +++ arts/gui/kde/kpopupbox_impl.cpp | 134 +++++ arts/gui/kde/kpopupbox_impl.h | 70 +++ arts/gui/kde/kpopupbox_private.h | 216 ++++++++ arts/gui/kde/kpoti.cpp | 780 ++++++++++++++++++++++++++++ arts/gui/kde/kpoti.h | 136 +++++ arts/gui/kde/kpoti_impl.cpp | 203 ++++++++ arts/gui/kde/kpoti_impl.h | 90 ++++ arts/gui/kde/kspinbox_impl.cpp | 108 ++++ arts/gui/kde/kspinbox_impl.h | 76 +++ arts/gui/kde/ktickmarks_impl.cpp | 179 +++++++ arts/gui/kde/ktickmarks_impl.h | 76 +++ arts/gui/kde/kvbox_impl.cpp | 51 ++ arts/gui/kde/kvbox_impl.h | 48 ++ arts/gui/kde/kvolumefader_impl.cpp | 243 +++++++++ arts/gui/kde/kvolumefader_impl.h | 97 ++++ arts/gui/kde/kwidget_impl.cpp | 181 +++++++ arts/gui/kde/kwidget_impl.h | 88 ++++ arts/gui/kde/kwidgetrepo.cpp | 89 ++++ arts/gui/kde/kwidgetrepo.h | 56 ++ arts/gui/kde/mcopclass/Button.mcopclass | 5 + arts/gui/kde/mcopclass/Fader.mcopclass | 5 + arts/gui/kde/mcopclass/Graph.mcopclass | 5 + arts/gui/kde/mcopclass/GraphLine.mcopclass | 5 + arts/gui/kde/mcopclass/HBox.mcopclass | 5 + arts/gui/kde/mcopclass/Label.mcopclass | 5 + arts/gui/kde/mcopclass/LayoutBox.mcopclass | 5 + arts/gui/kde/mcopclass/LevelMeter.mcopclass | 5 + arts/gui/kde/mcopclass/LineEdit.mcopclass | 5 + arts/gui/kde/mcopclass/Makefile.am | 5 + arts/gui/kde/mcopclass/PopupBox.mcopclass | 5 + arts/gui/kde/mcopclass/Poti.mcopclass | 5 + arts/gui/kde/mcopclass/SpinBox.mcopclass | 5 + arts/gui/kde/mcopclass/VBox.mcopclass | 5 + arts/gui/kde/mcopclass/Widget.mcopclass | 5 + 77 files changed, 6643 insertions(+) create mode 100644 arts/gui/kde/Makefile.am create mode 100644 arts/gui/kde/artstestgui.cpp create mode 100644 arts/gui/kde/dbtest.cpp create mode 100644 arts/gui/kde/dbtest.h create mode 100644 arts/gui/kde/dbvolcalc.h create mode 100644 arts/gui/kde/kartswidget.cpp create mode 100644 arts/gui/kde/kartswidget.h create mode 100644 arts/gui/kde/kbutton_impl.cpp create mode 100644 arts/gui/kde/kbutton_impl.h create mode 100644 arts/gui/kde/kcombobox_impl.cpp create mode 100644 arts/gui/kde/kcombobox_impl.h create mode 100644 arts/gui/kde/kfader.cpp create mode 100644 arts/gui/kde/kfader.h create mode 100644 arts/gui/kde/kfader_impl.cpp create mode 100644 arts/gui/kde/kfader_impl.h create mode 100644 arts/gui/kde/kframe_impl.cpp create mode 100644 arts/gui/kde/kframe_impl.h create mode 100644 arts/gui/kde/kgraph.cpp create mode 100644 arts/gui/kde/kgraph.h create mode 100644 arts/gui/kde/kgraph_impl.cpp create mode 100644 arts/gui/kde/kgraph_impl.h create mode 100644 arts/gui/kde/kgraphline_impl.cpp create mode 100644 arts/gui/kde/kgraphline_impl.h create mode 100644 arts/gui/kde/khbox_impl.cpp create mode 100644 arts/gui/kde/khbox_impl.h create mode 100644 arts/gui/kde/klabel_impl.cpp create mode 100644 arts/gui/kde/klabel_impl.h create mode 100644 arts/gui/kde/klayoutbox_impl.cpp create mode 100644 arts/gui/kde/klayoutbox_impl.h create mode 100644 arts/gui/kde/klevelmeter_firebars.cpp create mode 100644 arts/gui/kde/klevelmeter_firebars.h create mode 100644 arts/gui/kde/klevelmeter_impl.cpp create mode 100644 arts/gui/kde/klevelmeter_impl.h create mode 100644 arts/gui/kde/klevelmeter_linebars.cpp create mode 100644 arts/gui/kde/klevelmeter_linebars.h create mode 100644 arts/gui/kde/klevelmeter_normalbars.cpp create mode 100644 arts/gui/kde/klevelmeter_normalbars.h create mode 100644 arts/gui/kde/klevelmeter_private.h create mode 100644 arts/gui/kde/klevelmeter_small.cpp create mode 100644 arts/gui/kde/klevelmeter_small.h create mode 100644 arts/gui/kde/klevelmeter_template.h create mode 100644 arts/gui/kde/klineedit_impl.cpp create mode 100644 arts/gui/kde/klineedit_impl.h create mode 100644 arts/gui/kde/kpopupbox_impl.cpp create mode 100644 arts/gui/kde/kpopupbox_impl.h create mode 100644 arts/gui/kde/kpopupbox_private.h create mode 100644 arts/gui/kde/kpoti.cpp create mode 100644 arts/gui/kde/kpoti.h create mode 100644 arts/gui/kde/kpoti_impl.cpp create mode 100644 arts/gui/kde/kpoti_impl.h create mode 100644 arts/gui/kde/kspinbox_impl.cpp create mode 100644 arts/gui/kde/kspinbox_impl.h create mode 100644 arts/gui/kde/ktickmarks_impl.cpp create mode 100644 arts/gui/kde/ktickmarks_impl.h create mode 100644 arts/gui/kde/kvbox_impl.cpp create mode 100644 arts/gui/kde/kvbox_impl.h create mode 100644 arts/gui/kde/kvolumefader_impl.cpp create mode 100644 arts/gui/kde/kvolumefader_impl.h create mode 100644 arts/gui/kde/kwidget_impl.cpp create mode 100644 arts/gui/kde/kwidget_impl.h create mode 100644 arts/gui/kde/kwidgetrepo.cpp create mode 100644 arts/gui/kde/kwidgetrepo.h create mode 100644 arts/gui/kde/mcopclass/Button.mcopclass create mode 100644 arts/gui/kde/mcopclass/Fader.mcopclass create mode 100644 arts/gui/kde/mcopclass/Graph.mcopclass create mode 100644 arts/gui/kde/mcopclass/GraphLine.mcopclass create mode 100644 arts/gui/kde/mcopclass/HBox.mcopclass create mode 100644 arts/gui/kde/mcopclass/Label.mcopclass create mode 100644 arts/gui/kde/mcopclass/LayoutBox.mcopclass create mode 100644 arts/gui/kde/mcopclass/LevelMeter.mcopclass create mode 100644 arts/gui/kde/mcopclass/LineEdit.mcopclass create mode 100644 arts/gui/kde/mcopclass/Makefile.am create mode 100644 arts/gui/kde/mcopclass/PopupBox.mcopclass create mode 100644 arts/gui/kde/mcopclass/Poti.mcopclass create mode 100644 arts/gui/kde/mcopclass/SpinBox.mcopclass create mode 100644 arts/gui/kde/mcopclass/VBox.mcopclass create mode 100644 arts/gui/kde/mcopclass/Widget.mcopclass (limited to 'arts/gui/kde') diff --git a/arts/gui/kde/Makefile.am b/arts/gui/kde/Makefile.am new file mode 100644 index 00000000..5ebb3d0b --- /dev/null +++ b/arts/gui/kde/Makefile.am @@ -0,0 +1,38 @@ +SUBDIRS = mcopclass + +lib_LTLIBRARIES = libartsgui_kde.la + +check_PROGRAMS = artstestgui dbtest + +INCLUDES= -I$(top_builddir)/arts/runtime -I$(top_builddir)/arts/gui/common -I$(arts_includes) $(all_includes) + +libartsgui_kde_la_SOURCES = kwidget_impl.cpp kbutton_impl.cpp \ + kpoti_impl.cpp kpoti.cpp kwidgetrepo.cpp kartswidget.cpp \ + klineedit_impl.cpp khbox_impl.cpp kvbox_impl.cpp kspinbox_impl.cpp \ + kcombobox_impl.cpp kfader.cpp kfader_impl.cpp kgraph_impl.cpp kgraph.cpp \ + kgraphline_impl.cpp kframe_impl.cpp klayoutbox_impl.cpp kpopupbox_impl.cpp \ + klevelmeter_impl.cpp klevelmeter_small.cpp klevelmeter_linebars.cpp \ + klevelmeter_normalbars.cpp klevelmeter_firebars.cpp \ + ktickmarks_impl.cpp kvolumefader_impl.cpp klabel_impl.cpp + +libartsgui_kde_la_LIBADD = $(LIB_KIO) -lkdecore -lkdeui \ + $(top_builddir)/arts/gui/common/libartsgui_idl.la +libartsgui_kde_la_LDFLAGS = $(all_libraries) -no-undefined +libartsgui_kde_la_COMPILE_FIRST = ../common/artsgui.h + +artstestgui_SOURCES = artstestgui.cpp +artstestgui_LDADD = -lqtmcop -lkdecore -lartsflow \ + $(top_builddir)/arts/gui/common/libartsgui_idl.la +artstestgui_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +dbtest_SOURCES = dbtest.cpp +dbtest_LDADD = -lqtmcop -lkdecore -lartsflow \ + $(top_builddir)/arts/gui/kde/libartsgui_kde.la +dbtest_LDFLAGS = $(all_libraries) $(KDE_RPATH) + +libartsgui_kde_la_METASOURCES = AUTO + +####### install header files + +artsincludedir = $(includedir)/arts +artsinclude_HEADERS = kartswidget.h kframe_impl.h kwidget_impl.h kwidgetrepo.h klayoutbox_impl.h diff --git a/arts/gui/kde/artstestgui.cpp b/arts/gui/kde/artstestgui.cpp new file mode 100644 index 00000000..92f13163 --- /dev/null +++ b/arts/gui/kde/artstestgui.cpp @@ -0,0 +1,124 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#include "artsgui.h" +#include +#include +#include +#include +#include + +using namespace Arts; + +int main(int argc, char **argv) +{ + QIOManager iomanager; + Dispatcher dispatcher(&iomanager); + KApplication application(argc, argv, "testgui"); + + ObjectManager::the()->provideCapability("kdegui"); + + Widget w; + w.width(500); w.height(350); w.show(); + + Button b; + b.parent(w); + b.x(10); + b.y(10); + b.width(100); + b.height(20); + b.text("Hello World"); + b.show(); + + Button b2; + b2.parent(w); + b2.x(10); + b2.y(30); + b2.width(100); + b2.height(20); + b2.text("More World"); + b2.show(); + + Poti p; + p.parent(w); + p.x(150); + p.y(10); + p.caption("delay (ms)"); + p.color("red"); + p.min(10); + p.max(100); + p.value(90); + p.show(); + + Poti q; + q.parent(w); + q.x(250); + q.y(10); + q.caption("delay (ms)"); + q.color("blue"); + q.min(10); + q.max(100); + q.value(90); + q.show(); + + Graph g; + g.parent(w); + g.x(50); + g.y(70); + g.width(400); + g.height(230); + g.caption("a graph"); + g.minx(0.0); + g.maxx(1.0); + g.miny(0.0); + g.maxy(1.0); + g.show(); + + GraphLine gline; + gline.graph(g); + std::vector points; + points.push_back(GraphPoint(0, 1.0)); + points.push_back(GraphPoint(0.5, 1.0)); + points.push_back(GraphPoint(0.501, 0.0)); + points.push_back(GraphPoint(1.0, 0.0)); + gline.points(points); + gline.color("red"); + gline.editable(true); + + /* moves q if p is moved */ + connect(p,"value_changed",q,"value"); + +/* + connect(q,"value_changed",p,"value"); + + With the current assumptions that change notifications make, it is not + possible to connect p to q and q to p. + + The reason is that the notification will only be delivered some time + in the future (due to the requirement that they are asynchronous, i.e. + do not cause the sender to block) - but this means that two different + change notifications (i.e. changed to 1.0, changed to 2.0) may move + in a cycle between the two objects p and q, if p and q are cross + connected. So don't cross connect ;). +*/ + return application.exec(); +} diff --git a/arts/gui/kde/dbtest.cpp b/arts/gui/kde/dbtest.cpp new file mode 100644 index 00000000..164b3630 --- /dev/null +++ b/arts/gui/kde/dbtest.cpp @@ -0,0 +1,42 @@ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +dBTestWidget::dBTestWidget( QWidget* p, const char* n ) : QWidget( p,n ), dB2VolCalc( -24,6 ) { +kdDebug() << k_funcinfo << endl; + ( void* ) KStdAction::quit( this, SLOT( close() ), new KActionCollection( this ) ); + + for ( float i=0; i<=1; i+=0.25 ) + kdDebug() << i << " : " << amptodb( i ) << "dB" <show(); + app.setMainWidget( w ); + + return app.exec(); +} diff --git a/arts/gui/kde/dbtest.h b/arts/gui/kde/dbtest.h new file mode 100644 index 00000000..e7d996b0 --- /dev/null +++ b/arts/gui/kde/dbtest.h @@ -0,0 +1,16 @@ + +#ifndef DBTESTWIDGET_H +#define DBTESTWIDGET_H + +#include + +#include "dbvolcalc.h" + +class dBTestWidget : public QWidget, public dB2VolCalc { + Q_OBJECT +public: + dBTestWidget( QWidget*, const char* =0 ); + ~dBTestWidget(); +}; + +#endif diff --git a/arts/gui/kde/dbvolcalc.h b/arts/gui/kde/dbvolcalc.h new file mode 100644 index 00000000..8d99bf59 --- /dev/null +++ b/arts/gui/kde/dbvolcalc.h @@ -0,0 +1,82 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_DB2VOL_CALC_H +#define ARTS_DB2VOL_CALC_H + +#include + +class dB2VolCalc { +private: + float _base; +public: + dB2VolCalc( float _dbmin, float _dbmax ) + : _base( 6/log10( double(2) ) ) // Depends on what you measure: intensity(10), pressure(20), old artscontrol(6/lg2 (near 20)) + , dbmax( _dbmax ) + , dbmin( _dbmin ) + {} + + float dbmax, dbmin; + /** + Logarithmic/decimal valuation: + p = ampfactor ( linear ) + db = dezibel ( logarithmic ) + p = 10^( d/10 ) + db = 10*lg( p ) + + artscontrol was using + db = 6/ln( 2 ) * ln( p ) + which would be + db = 6/lg( 2 ) * lg( p ) + */ + float amptodb( float p ) { + float db = _base*log10( p ); + if ( db < dbmin ) db = dbmin; + if ( db > dbmax ) db = dbmax; + return db; + } + float dbtoamp( float db ) { + float amp = pow( 10, db/_base ); + if ( amp <= pow( 10, dbmin/_base ) ) amp = 0; + return amp; + } + /// With ndb = normalized dB (between 0 and 1) + float amptondb( float p ) { + return dbtondb( amptodb( p ) ); //- dbmin ) / ( dbmax - dbmin ); + } + float ndbtoamp( float ndb ) { + return dbtoamp( ndb * ( dbmax - dbmin ) + dbmin ); + } + /// Normalizes a dezibel value. + float dbtondb( float db ) { + return ( db - dbmin )/( dbmax - dbmin ); + } + /// Normalizes a volume to a logarithmic value between 0 and 1. + float dbtovol( float db ) { + return ( db -dbmin )/( 0-dbmin ); + } + /// Unnormalizes a dezibel value. + float ndbtodb( float ndb ) { + return ( ndb * ( dbmax-dbmin ) +dbmin ); + } +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kartswidget.cpp b/arts/gui/kde/kartswidget.cpp new file mode 100644 index 00000000..78f3bc3f --- /dev/null +++ b/arts/gui/kde/kartswidget.cpp @@ -0,0 +1,89 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + 2003 Arnold Krille + + 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. + + */ + +#include "kartswidget.h" +#include "kwidgetrepo.h" +#include "debug.h" +#include "qlayout.h" + +class KArtsWidgetPrivate { +public: + QHBoxLayout *layout; +}; + +KArtsWidget::KArtsWidget( QWidget* parent, const char* name ) + :QWidget( parent, name ), _content( Arts::Widget::null() ) +{ + d = new KArtsWidgetPrivate; + d->layout = new QHBoxLayout(this); +} + +KArtsWidget::KArtsWidget( Arts::Widget content, QWidget* parent, const char* name ) + :QWidget( parent, name ), _content( Arts::Widget::null()) +{ + d = new KArtsWidgetPrivate; + d->layout = new QHBoxLayout(this); + setContent(content); +} + +KArtsWidget::KArtsWidget( Arts::Widget content, QWidget* parent, const char* name, WFlags wflags ) + :QWidget( parent, name, wflags ), _content( Arts::Widget::null() ) +{ + d = new KArtsWidgetPrivate; + d->layout = new QHBoxLayout( this ); + setContent( content ); +} + +KArtsWidget::KArtsWidget(QWidget* parent, const char* name, WFlags wflags ) + :QWidget(parent, name, wflags ), _content(Arts::Widget::null()) +{ + d = new KArtsWidgetPrivate; + d->layout = new QHBoxLayout(this); +} + +KArtsWidget::~KArtsWidget() +{ + QWidget *contentAsWidget + = KWidgetRepo::the()->lookupQWidget(_content.widgetID()); + contentAsWidget->reparent(0,QPoint(0,0),_content.visible()); + delete d; + d = 0; +} + +/* TODO: change content (reparent old widget away, reparent new widget here) */ +void KArtsWidget::setContent(Arts::Widget content) +{ + arts_return_if_fail(!content.isNull()); + QWidget *contentAsWidget + = KWidgetRepo::the()->lookupQWidget(content.widgetID()); + arts_return_if_fail(contentAsWidget != 0); + + _content = content; + contentAsWidget->reparent(this,QPoint(0,0),content.visible()); + d->layout->addWidget(contentAsWidget); +} + +Arts::Widget KArtsWidget::content() +{ + return _content; +} diff --git a/arts/gui/kde/kartswidget.h b/arts/gui/kde/kartswidget.h new file mode 100644 index 00000000..049e4657 --- /dev/null +++ b/arts/gui/kde/kartswidget.h @@ -0,0 +1,92 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + 2003 Arnold Krille + + 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. + + */ + +#ifndef ARTS_GUI_KARTSWIDGET_H +#define ARTS_GUI_KARTSWIDGET_H + +#include +#include "artsgui.h" +#include +class KArtsWidgetPrivate; + +/** + * KArtsWidget provides a simple way to treat Arts::Widget classes like + * native Qt widgets. Suppose you use Qt, and want to put an Arts::Widget + * type into a layout, you can do so using this code + * + *
+ *    Arts::Widget widget = ...get widget from somewhere...;
+ *    KArtsWidget *w = new KArtsWidget(widget, this);
+ *    layout->addWidget(w);
+ * 
+ * + * In line 2 of the code, the "this" is the parent widget (which is usually + * this in Qt code). + * + * The KArtsWidget class keeps a reference to the content widget, so the + * content widget will not be freed until the KArtsWidget gets destroyed. + */ +class KDE_EXPORT KArtsWidget : public QWidget { +private: + KArtsWidgetPrivate *d; + +protected: + Arts::Widget _content; + +public: + /** + * creates a new KArtsWidget + */ + KArtsWidget( QWidget* parent, const char* name ); + + /** + * creates a new KArtsWidget and sets the content to an Arts::Widget + */ + KArtsWidget( Arts::Widget content, QWidget* parent, const char* name ); + + /** + * creates a new KArtsWidget with WidgetFlags and content + * + * BCI: should replace the above in the next major release. ( akrille ) + */ + KArtsWidget( Arts::Widget, QWidget* =0, const char* =0, WFlags =0 ); + // same without the content + KArtsWidget( QWidget* =0, const char* =0, WFlags =0 ); + + /** + * destructor + */ + ~KArtsWidget(); + + /** + * sets the content to a new Arts::Widget + */ + void setContent(Arts::Widget content); + + /** + * gets the content widget + */ + Arts::Widget content(); +}; + +#endif /* ARTS_GUI_KARTSWIDGET_H*/ diff --git a/arts/gui/kde/kbutton_impl.cpp b/arts/gui/kde/kbutton_impl.cpp new file mode 100644 index 00000000..eca30fcd --- /dev/null +++ b/arts/gui/kde/kbutton_impl.cpp @@ -0,0 +1,135 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + kretz@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. + + */ + +#include "kbutton_impl.h" +#include "kbutton_impl.moc" + +using namespace Arts; +using namespace std; + +KButtonMapper::KButtonMapper( KButton_impl *_impl, QPushButton *but ) + : QObject( but, "KButtonMapper" ) + , impl( _impl ) + , button( but ) +{ + connect( but, SIGNAL( pressed() ), this, SLOT( pressed() ) ); + connect( but, SIGNAL( released() ), this, SLOT( released() ) ); + connect( but, SIGNAL( toggled( bool ) ), this, SLOT( toggled( bool ) ) ); + connect( but, SIGNAL( clicked() ), this, SLOT( clicked() ) ); +} + +void KButtonMapper::pressed() +{ + if( ! button->isToggleButton() ) + impl->changeState(true); +} + +void KButtonMapper::released() +{ + if( ! button->isToggleButton() ) + impl->changeState(false); +} + +void KButtonMapper::toggled( bool b ) +{ + if( button->isToggleButton() ) + impl->changeState( b ); +} + +void KButtonMapper::clicked() +{ + impl->emitClicked(); +} + +KButton_impl::KButton_impl( QPushButton * widget ) + : KWidget_impl( widget ? widget : new QPushButton( 0 ) ) + , _clicked( false ) +{ + _qpushbutton = static_cast( _qwidget ); + ( void )new KButtonMapper( this, _qpushbutton ); +} + +void KButton_impl::constructor( Widget p ) +{ + parent( p ); +} + +void KButton_impl::constructor( const string & t, Widget p ) +{ + parent( p ); + text( t ); +} + +void KButton_impl::emitClicked() +{ + _clicked = true; + clicked_changed( true ); +} + +string KButton_impl::text() +{ + return _qpushbutton->text().utf8().data(); +} + +void KButton_impl::text(const string& newText) +{ + _qpushbutton->setText(QString::fromUtf8(newText.c_str())); +} + +bool KButton_impl::toggle() +{ + return _qpushbutton->isToggleButton(); +} + +void KButton_impl::toggle(bool newToggle) +{ + _qpushbutton->setToggleButton(newToggle); +} + +bool KButton_impl::pressed() +{ + if( _qpushbutton->isToggleButton() ) + return _qpushbutton->isOn(); + else + return _qpushbutton->isDown(); +} + +bool KButton_impl::clicked() +{ + if( _clicked ) + { + _clicked = false; + return true; + } + return false; +} + +void KButton_impl::changeState(bool newState) +{ + pressed_changed(newState); +} + +REGISTER_IMPLEMENTATION(KButton_impl); + +// vim:sw=4:ts=4 diff --git a/arts/gui/kde/kbutton_impl.h b/arts/gui/kde/kbutton_impl.h new file mode 100644 index 00000000..2c3c7163 --- /dev/null +++ b/arts/gui/kde/kbutton_impl.h @@ -0,0 +1,76 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + kretz@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. + + */ + +#ifndef ARTS_GUI_KBUTTON_IMPL_H +#define ARTS_GUI_KBUTTON_IMPL_H +#include "kwidget_impl.h" +#include + + +namespace Arts { +class KButton_impl; +class KButtonMapper : public QObject { + Q_OBJECT + KButton_impl *impl; + QPushButton * button; +public: + KButtonMapper(KButton_impl *impl, QPushButton *but); +protected slots: + void pressed(); + void released(); + void toggled( bool ); + void clicked(); +}; + +class KButton_impl : virtual public Arts::Button_skel, + public Arts::KWidget_impl +{ +private: + bool _clicked; + +protected: + QPushButton * _qpushbutton; + +public: + KButton_impl( QPushButton * w = 0 ); + void constructor( Widget parent ); + void constructor( const std::string &, Widget ); + + void emitClicked(); + + std::string text(); + void text(const std::string& newCaption); + + bool toggle(); + void toggle(bool); + + bool pressed(); + bool clicked(); + void changeState(bool); +}; + +} +#endif //ARTS_GUI_KBUTTON_IMPL_H + +// vim:sw=4:ts=4 diff --git a/arts/gui/kde/kcombobox_impl.cpp b/arts/gui/kde/kcombobox_impl.cpp new file mode 100644 index 00000000..dfa4e637 --- /dev/null +++ b/arts/gui/kde/kcombobox_impl.cpp @@ -0,0 +1,105 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + kretz@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. + + */ + +#include "kcombobox_impl.h" +#include "kcombobox_impl.moc" +#include "anyref.h" +#include "stdio.h" + +using namespace Arts; +using namespace std; + +ComboBoxIntMapper::ComboBoxIntMapper(KComboBox_impl *impl, KComboBox *co) + : QObject( co, "map Qt signal to aRts" ) + ,impl(impl) +{ + connect(co, SIGNAL(activated(const QString &)), this, SLOT(activated(const QString &))); +} + +void ComboBoxIntMapper::activated(const QString & newValue) +{ + impl->value(string(newValue.utf8().data())); +} + +KComboBox_impl::KComboBox_impl( KComboBox * widget ) + : KWidget_impl( widget ? widget : new KComboBox ) +{ + _kcombobox = static_cast( _qwidget ); + ( void )new ComboBoxIntMapper( this, _kcombobox ); +} + +string KComboBox_impl::caption() +{ + return m_caption.utf8().data(); +} + +void KComboBox_impl::caption(const string& newCaption) +{ + m_caption = QString::fromUtf8(newCaption.c_str()); + // FIXME: do something with the caption here +} + +vector * KComboBox_impl::choices() +{ + return new vector(m_choices); +} + +void KComboBox_impl::choices(const vector & newChoices) +{ + if(newChoices != m_choices) + { + m_choices = newChoices; + _kcombobox->clear(); + for(vector::const_iterator it = m_choices.begin(); it != m_choices.end(); ++it) + { + _kcombobox->insertItem(QString::fromUtf8(it->c_str())); + } + if(visible()) + choices_changed(newChoices); + } +} + +string KComboBox_impl::value() +{ + return m_value.utf8().data(); +} + +void KComboBox_impl::value(const string & newValue) +{ + if(newValue != m_value.utf8().data()) + { + m_value = QString::fromUtf8(newValue.c_str()); + for(unsigned int i = 0; i < m_choices.size(); ++i) + { + if(m_choices[i] == newValue) + _kcombobox->setCurrentItem(i); + } + if(visible()) + value_changed(newValue); + } +} + +REGISTER_IMPLEMENTATION(KComboBox_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kcombobox_impl.h b/arts/gui/kde/kcombobox_impl.h new file mode 100644 index 00000000..83222e3b --- /dev/null +++ b/arts/gui/kde/kcombobox_impl.h @@ -0,0 +1,74 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + kretz@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. + + */ + +#ifndef ARTS_GUI_KCOMBOBOX_IMPL_H +#define ARTS_GUI_KCOMBOBOX_IMPL_H +#include "kwidget_impl.h" +#include +#include +#include +#include + + +namespace Arts { + +class KComboBox_impl; +class ComboBoxIntMapper :public QObject { + Q_OBJECT + KComboBox_impl *impl; +public: + ComboBoxIntMapper(KComboBox_impl *impl, KComboBox *co); +public slots: + void activated(const QString &); +}; + +class KComboBox_impl : virtual public Arts::ComboBox_skel, + public Arts::KWidget_impl +{ +protected: + KComboBox * _kcombobox; + QString m_caption; + QString m_value; + std::vector m_choices; + + void applyValue(); + +public: + KComboBox_impl( KComboBox * w = 0 ); + void constructor( Widget p ) { parent( p ); } + + std::string caption(); + void caption(const std::string & newCaption); + + std::vector * choices(); + void choices(const std::vector & newChoices); + + std::string value(); + void value(const std::string & newValue); +}; + +} +#endif /* ARTS_GUI_KCOMBOBOX_IMPL_H */ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kfader.cpp b/arts/gui/kde/kfader.cpp new file mode 100644 index 00000000..2978dd0c --- /dev/null +++ b/arts/gui/kde/kfader.cpp @@ -0,0 +1,31 @@ +#include "kfader.h" +#include "kfader.moc" + +void KFader::init() +{ +} + +KFader::KFader( QWidget * parent, const char * name ) + : QSlider( Qt::Vertical, parent, name ) +{ + init(); +} + +KFader::KFader( int minValue, int maxValue, int pageStep, int value, QWidget * parent, const char * name ) + : QSlider( minValue, maxValue, pageStep, value, Qt::Vertical, parent, name ) +{ + init(); +} + +KFader::~KFader() +{ +} + +void KFader::setColor( QColor & ) +{ +} + +void KFader::setRange( int minValue, int maxValue ) +{ + QRangeControl::setRange( minValue, maxValue ); +} diff --git a/arts/gui/kde/kfader.h b/arts/gui/kde/kfader.h new file mode 100644 index 00000000..fcf53f21 --- /dev/null +++ b/arts/gui/kde/kfader.h @@ -0,0 +1,46 @@ + /* + + Copyright (C) 2001 Matthias Kretz + kretz@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. + + */ + +#ifndef _KFADER_H +#define _KFADER_H + +#include + +class KFader : public QSlider +{ + Q_OBJECT + protected: + void init(); + public: + KFader( QWidget * parent = 0, const char * name = 0 ); + KFader( int minValue, int maxValue, int pageStep, int value, QWidget * parent = 0, const char * name = 0 ); + + virtual ~KFader(); + + void setColor( QColor & ); + + virtual void setRange( int, int ); +}; + +#endif /* KFADER_H */ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kfader_impl.cpp b/arts/gui/kde/kfader_impl.cpp new file mode 100644 index 00000000..3304f3d3 --- /dev/null +++ b/arts/gui/kde/kfader_impl.cpp @@ -0,0 +1,206 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + kretz@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. + + */ + +#include "kfader_impl.h" +#include "kfader_impl.moc" +#include "anyref.h" +#include "stdio.h" + +#include + +using namespace Arts; +using namespace std; + +FaderIntMapper::FaderIntMapper(KFader_impl *impl, KFader *kp) :impl(impl) +{ + connect(kp, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int))); +} + +void FaderIntMapper::valueChanged(int pos) +{ + impl->valueChanged(pos); +} + +KFader_impl::KFader_impl( KFader * widget ) + : KWidget_impl( widget ? widget : new KFader( 0, 100, 1, 0 ) ) +{ + _min = 0; _max = 1; _value = 0; + _factor = 1; + _logarithmic = 0; + _range = 100; + + _kfader = static_cast( _qwidget ); + _kfader->setMinimumWidth( 40 ); + _kfader->setMinimumHeight( 100 ); + new FaderIntMapper( this, _kfader ); +} + +string KFader_impl::caption() +{ + return _caption.utf8().data(); +} + +void KFader_impl::caption(const string& newText) +{ + _caption = QString::fromUtf8(newText.c_str()); + _kfader->setName(_caption.utf8().data()); +} + +string KFader_impl::color() +{ + return _color; +} + +void KFader_impl::color(const string& newColor) +{ + _color = newColor; + if(strlen(_color.c_str())) + { + QColor qc(_color.c_str()); + _kfader->setColor(qc); + } +} + +float KFader_impl::min() +{ + return _min; +} + +void KFader_impl::min(float newMin) +{ + if(_min != newMin) + { + _min = newMin; + applyValue(); + } +} + +float KFader_impl::max() +{ + return _max; +} + +void KFader_impl::max(float newMax) +{ + if(_max != newMax) + { + _max = newMax; + applyValue(); + } +} + +float KFader_impl::value() +{ + //float ret = ( _max + _min - float(_kfader->value()) ) / _factor; + //if(_logarithmic > 0) + //ret = convertFromLog(ret); + float ret = _value; + if(ret < _min) + ret = _min; + else if(ret > _max) + ret = _max; + return ret; +} + +void KFader_impl::value(float newValue) +{ + if(newValue != _value) + { + _value = newValue; + applyValue(); + if(visible()) + value_changed(value()); + } +} + +long KFader_impl::range() +{ + return _range; +} + +void KFader_impl::range(long newRange) +{ + if(_range != newRange) + { + _range = newRange; + applyValue(); + } +} + +void KFader_impl::valueChanged(int newvalue) +{ + _value = float(newvalue) / _factor; + if(_logarithmic > 0) + _value = convertFromLog(_value); + _value = _max + _min - _value; + if(visible()) + value_changed(value()); +} + +float KFader_impl::convertToLog(float val) +{ + return log(val) / log(_logarithmic); +} + +float KFader_impl::convertFromLog(float val) +{ + return pow(_logarithmic, val); +} + +void KFader_impl::applyValue() +{ + double dmin = _min; + double dmax = _max; + double dvalue = _value; + if(_logarithmic > 0) + { + dmin = convertToLog(_min); + dmax = convertToLog(_max); + dvalue = convertToLog(_value); + } + _factor = _range / (dmax - dmin); + int imin = int(_factor * dmin); + int imax = int(_factor * dmax); + int ivalue = int(_factor * (dmax + dmin - dvalue)); + _kfader->setRange(imin, imax); + _kfader->setValue(ivalue); +} + +void KFader_impl::logarithmic(float newLogarithmic) +{ + if(_logarithmic != newLogarithmic) + { + _logarithmic = newLogarithmic; + applyValue(); + } +} + +float KFader_impl::logarithmic() +{ + return _logarithmic; +} + +REGISTER_IMPLEMENTATION(KFader_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kfader_impl.h b/arts/gui/kde/kfader_impl.h new file mode 100644 index 00000000..55419cff --- /dev/null +++ b/arts/gui/kde/kfader_impl.h @@ -0,0 +1,92 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + kretz@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. + + */ + +#ifndef ARTS_GUI_KFADER_IMPL_H +#define ARTS_GUI_KFADER_IMPL_H +#include "kwidget_impl.h" +#include "kfader.h" + +#include +#include + + +namespace Arts { + +class KFader_impl; + +class FaderIntMapper :public QObject { + Q_OBJECT + KFader_impl *impl; +public: + FaderIntMapper(KFader_impl *impl, KFader *kp); +public slots: + void valueChanged(int x); +}; + +class KFader_impl : virtual public Arts::Fader_skel, + public Arts::KWidget_impl +{ +protected: + KFader * _kfader; + QString _caption; + std::string _color; + float _min, _max, _value; + float _factor; + float _logarithmic; + long _range; + + float convertToLog(float); + float convertFromLog(float); + void applyValue(); + +public: + KFader_impl( KFader * w = 0 ); + void constructor( Widget p ) { parent( p ); } + + std::string caption(); + void caption(const std::string& newText); + std::string color(); + void color(const std::string& newColor); + + float logarithmic(); + void logarithmic(float); + + float min(); + void min(float newMin); + float max(); + void max(float newMax); + float value(); + void value(float newValue); + + long range(); + void range(long newRange); + + /* from qt */ + void valueChanged(int newValue); +}; + +} +#endif /* ARTS_GUI_KFADER_IMPL_H */ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kframe_impl.cpp b/arts/gui/kde/kframe_impl.cpp new file mode 100644 index 00000000..a2fc6d8c --- /dev/null +++ b/arts/gui/kde/kframe_impl.cpp @@ -0,0 +1,98 @@ +/* + Copyright (C) 2002 Matthias Kretz + + 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. + +*/ +// $Id$ + +#include "kframe_impl.h" +#include +#include +#include + +using namespace Arts; +using namespace std; + +KFrame_impl::KFrame_impl( QFrame * widget ) + : KWidget_impl( widget ? widget : new QFrame ) +{ + _qframe = static_cast( _qwidget ); + assert( _qframe ); +} + +long KFrame_impl::margin() +{ + return _qframe->margin(); +} + +void KFrame_impl::margin( long m ) +{ + _qframe->setMargin( m ); +} + +long KFrame_impl::linewidth() +{ + return _qframe->lineWidth(); +} + +void KFrame_impl::linewidth( long lw ) +{ + _qframe->setLineWidth( lw ); +} + +long KFrame_impl::midlinewidth() +{ + return _qframe->midLineWidth(); +} + +void KFrame_impl::midlinewidth( long mlw ) +{ + _qframe->setMidLineWidth( mlw ); +} + +long KFrame_impl::framestyle() +{ + return _qframe->frameStyle(); +} + +void KFrame_impl::framestyle( long fs ) +{ + _qframe->setFrameStyle( fs ); +} + +Shape KFrame_impl::frameshape() +{ + return ( Shape )_qframe->frameShape(); +} + +void KFrame_impl::frameshape( Shape fs ) +{ + _qframe->setFrameShape( ( QFrame::Shape )fs ); +} + +Shadow KFrame_impl::frameshadow() +{ + return ( Shadow )_qframe->frameShadow(); +} + +void KFrame_impl::frameshadow( Shadow fs ) +{ + _qframe->setFrameShadow( ( QFrame::Shadow )fs ); +} + +REGISTER_IMPLEMENTATION(KFrame_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kframe_impl.h b/arts/gui/kde/kframe_impl.h new file mode 100644 index 00000000..3b4bcb69 --- /dev/null +++ b/arts/gui/kde/kframe_impl.h @@ -0,0 +1,55 @@ +/* + Copyright (C) 2002 Matthias Kretz + + 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. + +*/ +// $Id$ + +#ifndef KFRAME_IMPL +#define KFRAME_IMPL +#include "kwidget_impl.h" +#include +class QFrame; + +namespace Arts { + +class KDE_EXPORT KFrame_impl : virtual public Arts::Frame_skel, + public Arts::KWidget_impl +{ + protected: + QFrame * _qframe; + + public: + KFrame_impl( QFrame * widget = 0 ); + inline void constructor( Widget p ) { parent( p ); } + + long margin(); + void margin( long m ); + long linewidth(); + void linewidth( long lw ); + long midlinewidth(); + void midlinewidth( long mlw ); + long framestyle(); + void framestyle( long fs ); + Shape frameshape(); + void frameshape( Shape fs ); + Shadow frameshadow(); + void frameshadow( Shadow fs ); +}; //class +} //namespace + +// vim: sw=4 ts=4 +#endif diff --git a/arts/gui/kde/kgraph.cpp b/arts/gui/kde/kgraph.cpp new file mode 100644 index 00000000..e7797692 --- /dev/null +++ b/arts/gui/kde/kgraph.cpp @@ -0,0 +1,266 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#include "kgraph.h" +#include "kgraph.moc" +#include "kgraphline_impl.h" +#include "qpainter.h" + +#include +#include + +using namespace Arts; +using namespace std; + +KGraph::KGraph( QWidget * parent, const char * name ) + : QWidget( parent, name ) +{ + setBackgroundColor(white); + + selectedIndex = -1; + minx = miny = 0.0; + maxx = maxy = 1.0; +} + +KGraph::~KGraph() +{ +} + +void KGraph::addLine(Arts::KGraphLine_impl *line) +{ + lines.push_back(line); +} + +void KGraph::redrawLine(Arts::KGraphLine_impl * /*line*/) +{ + repaint(); +} + +void KGraph::removeLine(Arts::KGraphLine_impl *line) +{ + if(line == selectedLine) + { + selectedLine = 0; + selectedIndex = -1; + } + lines.remove(line); +} + +inline QPoint KGraph::g2qPoint(const GraphPoint &gp) +{ + return QPoint(int(((gp.x - minx)/(maxx-minx)) * (width()-1)), + int((1.0 - (gp.y - miny)/(maxy-miny)) * (height()-1))); +} + +inline GraphPoint KGraph::q2gPoint(const QPoint &qp) +{ + return GraphPoint((float(qp.x())/float(width()-1)) * (maxx-minx) + minx, + (1.0 - (float(qp.y())/float(height()-1))) * (maxy-miny) + miny); +} + +void KGraph::paintEvent( QPaintEvent *e ) +{ + QPainter painter(this); + painter.setClipRect(e->rect()); + + std::list::iterator li; + for(li = lines.begin(); li != lines.end(); li++) + { + KGraphLine_impl *gline = *li; + + vector::iterator pi; + QPoint lastp; + bool first = true; + + painter.setPen(gline->_color.c_str()); + + for(pi = gline->_points.begin(); pi != gline->_points.end(); pi++) + { + QPoint p = g2qPoint(*pi); + + if(!first) + painter.drawLine(lastp,p); + + if(gline->_editable) + painter.drawEllipse(p.x()-3,p.y()-3,7,7); + + lastp = p; + first = false; + } + } +} + +void KGraph::mousePressEvent(QMouseEvent *e) +{ + if(e->button() == LeftButton || e->button() == RightButton) + { + std::list::iterator li; + for(li = lines.begin(); li != lines.end(); li++) + { + KGraphLine_impl *gline = *li; + + vector::iterator pi; + int index = 0; + for(pi = gline->_points.begin(); pi != gline->_points.end(); pi++, index++) + { + QPoint p = g2qPoint(*pi); + + int dx = e->x() - p.x(); + int dy = e->y() - p.y(); + + if(::sqrt(double(dx*dx + dy*dy)) < 5.0) + { + selectedIndex = index; + selectedLine = gline; + selectedPoint = *pi; + } + } + } + } + + if(selectedIndex >= 0) + { + // erase point + if(e->button() == RightButton) + { + if(selectedIndex != 0 && selectedIndex != (( int )( selectedLine->_points.size() )-1)) + { + vector points; + + for(int i=0;i<( int )selectedLine->_points.size();i++) + { + if(selectedIndex != i) + points.push_back(selectedLine->_points[i]); + } + + selectedLine->points(points); + } + + selectedLine = 0; + selectedIndex = -1; + } + } + else if(e->button() == LeftButton) + { + // try to insert a point + std::list::iterator li; + for(li = lines.begin(); li != lines.end(); li++) + { + KGraphLine_impl *gline = *li; + + QPoint lastp; + bool first = true; + + vector::iterator pi; + int index = 0; + for(pi = gline->_points.begin(); pi != gline->_points.end(); pi++, index++) + { + QPoint p = g2qPoint(*pi); + + if(!first && (e->x() > lastp.x()+2) && (e->x() < p.x()-2)) + { + float pos = float(e->x()-lastp.x())/float(p.x()-lastp.x()); + int y = (int)((1.0-pos) * lastp.y() + pos * p.y()); + + if(abs(y-e->y()) < 5) + { + GraphPoint gp = q2gPoint(QPoint(e->x(),y)); + vector newPoints; + + for(int i=0;i<( int )gline->_points.size();i++) + { + if(index == i) + newPoints.push_back(gp); + newPoints.push_back(gline->_points[i]); + } + gline->points(newPoints); + + selectedLine = gline; + selectedIndex = index; + selectedPoint = gp; + + return; + } + } + lastp = p; + first = false; + } + } + } +} + +void KGraph::mouseMoveEvent(QMouseEvent *e) +{ + QPoint pos = e->pos(); + + if(pos.x() < 0) pos.setX(0); + if(pos.y() < 0) pos.setY(0); + if(pos.x() >= width()) pos.setX(width()-1); + if(pos.y() >= height()) pos.setY(height()-1); + + if(selectedIndex >= 0) + { + vector points(selectedLine->_points); + + + if((( int )points.size() <= selectedIndex) + || (fabs(selectedPoint.x-points[selectedIndex].x) > 0.000001) + || (fabs(selectedPoint.y-points[selectedIndex].y) > 0.000001)) + { + selectedLine = 0; + selectedIndex = -1; + return; // line was modified from somewhere else, meanwhile + } + + // I am not sure whether we always want to constrain it that way + GraphPoint gp = q2gPoint(pos); + selectedPoint.y = gp.y; + + if(selectedIndex != 0 && selectedIndex != (( int )( points.size() )-1)) + { + float pixelsize = (maxx-minx)/float(width()-1); + + if(selectedIndex > 0 && points[selectedIndex-1].x > gp.x) + { + selectedPoint.x = points[selectedIndex-1].x+pixelsize; + } + else if(selectedIndex < (( int )( points.size() )-1) && points[selectedIndex+1].x < gp.x) + { + selectedPoint.x = points[selectedIndex+1].x-pixelsize; + } + else + { + selectedPoint.x = gp.x; + } + } + points[selectedIndex] = selectedPoint; + selectedLine->points(points); + } +} + +void KGraph::mouseReleaseEvent(QMouseEvent *) +{ + selectedIndex = -1; + selectedLine = 0; +} + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kgraph.h b/arts/gui/kde/kgraph.h new file mode 100644 index 00000000..51e64d70 --- /dev/null +++ b/arts/gui/kde/kgraph.h @@ -0,0 +1,64 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#ifndef _KGRAPH_H +#define _KGRAPH_H + +#include +#include +#include "artsgui.h" +#include + +namespace Arts { + +class KGraphLine_impl; +class KGraph : public QWidget +{ +Q_OBJECT + +protected: + std::list lines; + float minx, maxx, miny, maxy; + + KGraphLine_impl *selectedLine; + GraphPoint selectedPoint; + int selectedIndex; // -1 if nothing is selected + + inline GraphPoint q2gPoint(const QPoint &qp); + inline QPoint g2qPoint(const GraphPoint &gp); +public: + KGraph( QWidget * parent = 0, const char * name = 0 ); + virtual ~KGraph(); + + void addLine(Arts::KGraphLine_impl *line); + void redrawLine(Arts::KGraphLine_impl *line); + void removeLine(Arts::KGraphLine_impl *line); + + void mousePressEvent(QMouseEvent *me); + void mouseMoveEvent(QMouseEvent *me); + void mouseReleaseEvent(QMouseEvent *me); + + void paintEvent(QPaintEvent *e); +}; +} + +#endif /* KGRAPH_H */ diff --git a/arts/gui/kde/kgraph_impl.cpp b/arts/gui/kde/kgraph_impl.cpp new file mode 100644 index 00000000..f629e680 --- /dev/null +++ b/arts/gui/kde/kgraph_impl.cpp @@ -0,0 +1,92 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#include "kgraph_impl.h" +#include "anyref.h" +#include "stdio.h" + +using namespace Arts; +using namespace std; + +KGraph_impl::KGraph_impl( KGraph * widget ) + : KWidget_impl( widget ? widget : new KGraph ) +{ + _minx = 0.0; _maxx = 1.0; _miny = 0.0; _maxy = 1.0; + _kgraph = static_cast( _qwidget ); + _kgraph->setFixedSize( 300, 200 ); +} + +string KGraph_impl::caption() +{ + return _caption.utf8().data(); +} + +void KGraph_impl::caption(const string& newCaption) +{ + _caption = QString::fromUtf8(newCaption.c_str()); + // FIXME: do something with the caption here +} + +float KGraph_impl::minx() +{ + return _minx; +} + +void KGraph_impl::minx(float newMin) +{ + _minx = newMin; +} + +float KGraph_impl::maxx() +{ + return _maxx; +} + +void KGraph_impl::maxx(float newMax) +{ + _maxx = newMax; +} + +float KGraph_impl::miny() +{ + return _miny; +} + +void KGraph_impl::miny(float newMin) +{ + _miny = newMin; +} + +float KGraph_impl::maxy() +{ + return _maxy; +} + +void KGraph_impl::maxy(float newMax) +{ + _maxy = newMax; +} + +namespace Arts { REGISTER_IMPLEMENTATION(KGraph_impl); } + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kgraph_impl.h b/arts/gui/kde/kgraph_impl.h new file mode 100644 index 00000000..b576d65a --- /dev/null +++ b/arts/gui/kde/kgraph_impl.h @@ -0,0 +1,65 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#ifndef ARTS_GUI_KGRAPH_IMPL_H +#define ARTS_GUI_KGRAPH_IMPL_H +#include "kwidget_impl.h" +#include "kgraph.h" + +#include +#include + + +namespace Arts { + +class KGraph_impl; + +class KGraph_impl : virtual public Arts::Graph_skel, + public Arts::KWidget_impl +{ +protected: + QString _caption; + float _minx, _miny, _maxx, _maxy; + + KGraph * _kgraph; + +public: + KGraph_impl( KGraph * w = 0 ); + void constructor( Widget p ) { parent( p ); } + + std::string caption(); + void caption(const std::string& newCaption); + + float minx(); + void minx(float newMin); + float maxx(); + void maxx(float newMax); + float miny(); + void miny(float newMin); + float maxy(); + void maxy(float newMax); +}; + +} +#endif /* ARTS_GUI_KGRAPH_IMPL_H */ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kgraphline_impl.cpp b/arts/gui/kde/kgraphline_impl.cpp new file mode 100644 index 00000000..5a48c000 --- /dev/null +++ b/arts/gui/kde/kgraphline_impl.cpp @@ -0,0 +1,124 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#include "kgraphline_impl.h" +#include "kwidgetrepo.h" +#include "kgraph.h" + +using namespace Arts; +using namespace std; + +KGraphLine_impl::KGraphLine_impl() +{ + _graphID = -1; +} + +KGraphLine_impl::~KGraphLine_impl() +{ + KGraph *kgraph = getKGraph(); + if(kgraph) + kgraph->removeLine(this); +} + +Graph KGraphLine_impl::graph() +{ + return Arts::DynamicCast(KWidgetRepo::the()->lookupWidget(_graphID)); +} + +void KGraphLine_impl::graph(Graph newGraph) +{ + KGraph *kgraph = getKGraph(); + if(kgraph) + kgraph->removeLine(this); + + _graphID = newGraph.widgetID(); + + kgraph = getKGraph(); + if(kgraph) + kgraph->addLine(this); +} + +bool KGraphLine_impl::editable() +{ + return _editable; +} + +void KGraphLine_impl::editable(bool newEditable) +{ + _editable = newEditable; + + KGraph *kgraph = getKGraph(); + if(kgraph) + kgraph->redrawLine(this); +} + +string KGraphLine_impl::color() +{ + return _color; +} + +void KGraphLine_impl::color(const std::string& newColor) +{ + _color = newColor; + + KGraph *kgraph = getKGraph(); + if(kgraph) + kgraph->redrawLine(this); +} + +vector *KGraphLine_impl::points() +{ + return new vector(_points); +} + +void KGraphLine_impl::points(const vector& newPoints) +{ + _points = newPoints; + + KGraph *kgraph = getKGraph(); + if(kgraph) + kgraph->redrawLine(this); + + // emitting a change notification is a bit tricky because no real + // Arts::AnyRef support is there for sequence + Arts::Any any; + Arts::Buffer buffer; + + any.type = "*Arts::GraphPoint"; + writeTypeSeq(buffer,_points); + buffer.read(any.value,buffer.size()); + + _emit_changed("points_changed",any); +} + +KGraph *KGraphLine_impl::getKGraph() +{ + QWidget *widget = KWidgetRepo::the()->lookupQWidget(_graphID); + if(!widget) + return 0; + + return dynamic_cast(widget); +} + +namespace Arts { + REGISTER_IMPLEMENTATION(KGraphLine_impl); +} diff --git a/arts/gui/kde/kgraphline_impl.h b/arts/gui/kde/kgraphline_impl.h new file mode 100644 index 00000000..546cff90 --- /dev/null +++ b/arts/gui/kde/kgraphline_impl.h @@ -0,0 +1,61 @@ + /* + + Copyright (C) 2001 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#ifndef _KGRAPHLINE_IMPL_H +#define _KGRAPHLINE_IMPL_H + +#include "artsgui.h" + +namespace Arts { + +class KGraph; +class KGraphLine_impl : virtual public GraphLine_skel { +protected: + friend class KGraph; // for efficiency + + long _graphID; + bool _editable; + std::string _color; + std::vector _points; + + KGraph *getKGraph(); + +public: + KGraphLine_impl(); + ~KGraphLine_impl(); + + Graph graph(); + void graph(Graph newGraph); + + bool editable(); + void editable(bool newEditable); + + std::string color(); + void color(const std::string& newColor); + + std::vector *points(); + void points(const std::vector& newPoints); +}; + +} + +#endif /* _KGRAPHLINE_IMPL_H */ diff --git a/arts/gui/kde/khbox_impl.cpp b/arts/gui/kde/khbox_impl.cpp new file mode 100644 index 00000000..90ed9a3b --- /dev/null +++ b/arts/gui/kde/khbox_impl.cpp @@ -0,0 +1,51 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#include "khbox_impl.h" +#include + +using namespace Arts; + +KHBox_impl::KHBox_impl( QHBox * widget ) + : KFrame_impl( widget ? widget : new QHBox ) + , _spacing( 5 ) +{ + _qhbox = static_cast( _qwidget ); + _qhbox->setSpacing( _spacing ); + _qhbox->setMargin( 5 ); +} + +long KHBox_impl::spacing() +{ + return _spacing; +} + +void KHBox_impl::spacing( long s ) +{ + _spacing = s; + _qhbox->setSpacing( s ); +} + +REGISTER_IMPLEMENTATION(KHBox_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/khbox_impl.h b/arts/gui/kde/khbox_impl.h new file mode 100644 index 00000000..70bade71 --- /dev/null +++ b/arts/gui/kde/khbox_impl.h @@ -0,0 +1,48 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#include "kframe_impl.h" + +class QHBox; + +namespace Arts { + +class KHBox_impl : virtual public Arts::HBox_skel, + public Arts::KFrame_impl +{ +private: + long _spacing; + +protected: + QHBox * _qhbox; + +public: + KHBox_impl( QHBox * w = 0 ); + + long spacing(); + void spacing( long ); +}; + +} + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klabel_impl.cpp b/arts/gui/kde/klabel_impl.cpp new file mode 100644 index 00000000..f53de2e7 --- /dev/null +++ b/arts/gui/kde/klabel_impl.cpp @@ -0,0 +1,104 @@ +/* + Copyright ( C ) 2002 Arnold Krille + + 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. + +*/ + +#include "klabel_impl.h" +#include "klabel_impl.moc" + +#include +#include + +using namespace Arts; +using namespace std; + +KLabel_impl::KLabel_impl( QFrame *widget ) : KFrame_impl( widget ? widget : new RotateLabel( 0 ) ) { + _label = static_cast( _qwidget ); +} + +string KLabel_impl::text() { + return _label->title().utf8().data(); +} + +void KLabel_impl::text( const string& newtext ) { + _label->title( QString::fromUtf8( newtext.c_str() ) ); +} + +long KLabel_impl::align() { return _label->align(); } +void KLabel_impl::align( long n ) { _label->align( n ); } + +void KLabel_impl::fontsize( long n ) { _label->fontsize( n ); } +void KLabel_impl::fontfamily( const std::string& n ) { _label->fontfamily( n.c_str() ); } + +Arts::TextBottom KLabel_impl::bottom() { return _label->bottom(); } +void KLabel_impl::bottom( Arts::TextBottom n ) { _label->bottom( n ); } + +REGISTER_IMPLEMENTATION( KLabel_impl ); + +RotateLabel::RotateLabel( QWidget* p, const char* n ) : QFrame( p,n ) { + _bottom = Arts::South; + _align = Arts::AlignCenter; +} +void RotateLabel::paintEvent( QPaintEvent* ) { + QPainter p( this ); + if ( _bottom == Arts::East ) { + p.rotate( 270 ); + p.drawText( QRect( 0,0, -height(), width() ), _align, _title ); + } else if ( _bottom == Arts::West ) { + p.rotate( 90 ); + p.drawText( QRect( 0,0, height(), -width() ), _align, _title ); + } else if ( _bottom == Arts::North ) { + p.rotate( 180 ); + p.drawText( QRect( 0,0, -width(), -height() ), _align, _title ); + } else { + p.drawText( QRect( 0,0, width(), height() ), _align, _title ); + } +} + +void RotateLabel::fontfamily( QString n ) { + QFont font = this->font(); + font.setFamily( n ); + this->setFont( font ); +} +void RotateLabel::fontsize( int n ) { + QFont font = this->font(); + font.setPixelSize( n ); + this->setFont( font ); +} + +void RotateLabel::title( QString n ) { + _title = n; + QSize size = this->fontMetrics().size( SingleLine, _title ); + if ( _bottom == Arts::East || _bottom == Arts::West ) + this->setMinimumSize( size.height(), size.width() ); + else + this->setMinimumSize( size ); +} + +void RotateLabel::align( long n ) { + _align=n; + repaint(); +} + +void RotateLabel::bottom( Arts::TextBottom bottom ) { + _bottom = bottom; + title( _title ); + repaint(); +} + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klabel_impl.h b/arts/gui/kde/klabel_impl.h new file mode 100644 index 00000000..62b505a3 --- /dev/null +++ b/arts/gui/kde/klabel_impl.h @@ -0,0 +1,90 @@ + /* + + Copyright ( C ) 2002 Arnold Krille + + 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. + + */ + +#ifndef ARTS_KLABEL_IMPL +#define ARTS_KLABEL_IMPL + +#include +#include +#include +#include +#include + +#include +#include + +class RotateLabel; + +namespace Arts { + +class KDE_EXPORT KLabel_impl : virtual public Arts::Label_skel, + public Arts::KFrame_impl +{ +protected: + RotateLabel* _label; +public: + KLabel_impl( QFrame* w=0 ); + void constructor( Widget p ) { parent( p ); } + + std::string text(); + void text( const std::string& newtext ); + + long align(); + void align( long ); + + long fontsize() { return -1; } + void fontsize( long ); + + std::string fontfamily() { return ""; } + void fontfamily( const std::string& ); + + Arts::TextBottom bottom(); + void bottom( Arts::TextBottom ); + +}; // class + +} // namespace + +class RotateLabel : public QFrame { + Q_OBJECT +public: + RotateLabel( QWidget*, const char* =0 ); + void paintEvent( QPaintEvent* ); + + void fontfamily( QString ); + void fontsize( int ); + void title( QString ); + QString title() { return _title; } + + long align() { return _align; } + void align( long ); + + Arts::TextBottom bottom() { return _bottom; } + void bottom( Arts::TextBottom ); +private: + long _align; + Arts::TextBottom _bottom; + QString _title; +}; + +#endif + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klayoutbox_impl.cpp b/arts/gui/kde/klayoutbox_impl.cpp new file mode 100644 index 00000000..e83ea5c7 --- /dev/null +++ b/arts/gui/kde/klayoutbox_impl.cpp @@ -0,0 +1,122 @@ +/* + Copyright ( C ) 2002, 2003 Arnold Krille + + 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. + +*/ + +#include "klayoutbox_impl.h" + +#include +#include +#include +#include +#include +#include +#include "kwidgetrepo.h" + +using namespace Arts; +using namespace std; + +KLayoutBox_impl::KLayoutBox_impl( QFrame *widget ) : KFrame_impl( widget ? widget :new QFrame( 0 ) ) +{ + _qframe = static_cast( _qwidget ); + _layout = new QBoxLayout( _qframe, QBoxLayout::LeftToRight ); +} +KLayoutBox_impl::~KLayoutBox_impl() { +} + +void KLayoutBox_impl::addWidget( Arts::Widget widget, long stretch, long align ) { + widget.parent( self() ); + this->_addChild( widget, "layoutbox_item" ); + QWidget * tmp = KWidgetRepo::the()->lookupQWidget( widget.widgetID() ); + _layout->addWidget( tmp, stretch, align ); +} + +void KLayoutBox_impl::insertWidget( long index, Arts::Widget widget, long stretch, long align ) { + widget.parent( self() ); + this->_addChild( widget, "layoutbox_item" ); + QWidget * tmp = KWidgetRepo::the()->lookupQWidget( widget.widgetID() ); + _layout->insertWidget( index, tmp, stretch, align ); +} + +void KLayoutBox_impl::addStretch( long n ) { _layout->addStretch( n ); } +void KLayoutBox_impl::addSpace( long n ) { _layout->addSpacing( n ); } +void KLayoutBox_impl::addStrut( long n ) { _layout->addStrut( n ); } +void KLayoutBox_impl::addSeparator( long stretch, long align ) { + _layout->addWidget( new KLayoutBox_Separator( _qframe ), stretch, align ); +} +void KLayoutBox_impl::addLine( long width, long space, long stretch, long align ) { + _layout->addWidget( new KLayoutBox_Line( width, space, _qframe ), stretch, align ); +} + +long KLayoutBox_impl::spacing() { return _layout->spacing(); } +void KLayoutBox_impl::spacing( long n ) { _layout->setSpacing( n ); } + +long KLayoutBox_impl::layoutmargin() { return _layout->margin(); } +void KLayoutBox_impl::layoutmargin( long n ) { _layout->setMargin( n ); this->margin( n ); } + +Direction KLayoutBox_impl::direction() { return Arts::Direction( _layout->direction() ); } +void KLayoutBox_impl::direction( Direction d ) { _layout->setDirection( QBoxLayout::Direction( d ) ); } + +REGISTER_IMPLEMENTATION( KLayoutBox_impl ); + +KLayoutBox_Separator::KLayoutBox_Separator( QWidget* p, const char* n ) : QWidget( p,n ) { +//kdDebug() << k_funcinfo << endl; +} + +void KLayoutBox_Separator::resizeEvent( QResizeEvent* ) { kdDebug() << k_funcinfo << size() << endl; } + +void KLayoutBox_Separator::paintEvent( QPaintEvent* ) { +//kdDebug() << k_funcinfo << size() << endl; + QPainter p( this ); + QStyle::SFlags flags = QStyle::Style_Default; + if ( width() < height() ) flags |= QStyle::Style_Horizontal; + style().drawPrimitive( QStyle::PE_Splitter, &p, rect(), colorGroup(), flags ); +} + +QSize KLayoutBox_Separator::minimumSizeHint() const { + int wh = style().pixelMetric( QStyle::PM_SplitterWidth, this ); + return QSize( wh, wh ); +} + +KLayoutBox_Line::KLayoutBox_Line( int width, int space, QWidget* p, const char* n ) + : QWidget( p,n ) + , _width( width ) + , _space( space ) +{ +//kdDebug() << k_funcinfo << size() << endl; +} + + +void KLayoutBox_Line::paintEvent( QPaintEvent* ) { +//kdDebug() << k_funcinfo << size() << endl; + QPainter p( this ); + p.setPen( QPen( colorGroup().foreground(), _width ) ); + if ( width() > height() ) p.drawLine( 0, height()/2, width(), height()/2 ); + else p.drawLine( width()/2, 0, width()/2, height() ); +} + +QSize KLayoutBox_Line::minimumSizeHint() const { +//kdDebug() << k_funcinfo << size() << endl; + int wh = _width + 2* _space; + return QSize( wh, wh ); +} + +#include + +// vim: sw=4 ts=4 + diff --git a/arts/gui/kde/klayoutbox_impl.h b/arts/gui/kde/klayoutbox_impl.h new file mode 100644 index 00000000..fbb88630 --- /dev/null +++ b/arts/gui/kde/klayoutbox_impl.h @@ -0,0 +1,103 @@ + /* + + Copyright ( C ) 2002, 2003 Arnold Krille + + 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. + + */ + +#ifndef ARTS_KLAYOUTBOX_IMPL_H +#define ARTS_KLAYOUTBOX_IMPL_H + +#include "kframe_impl.h" + +#include +#include + +class KArtsWidget; +class QBoxLayout; + +namespace Arts { + +class KDE_EXPORT KLayoutBox_impl : virtual public Arts::LayoutBox_skel, + public Arts::KFrame_impl +{ +protected: + QFrame* _qframe; + QBoxLayout* _layout; + + LayoutBox self() { return LayoutBox::_from_base( _copy() ); } +public: + KLayoutBox_impl( QFrame* w=0 ); + ~KLayoutBox_impl(); + + Direction direction(); + void direction( Direction ); + + void addWidget( Arts::Widget, long, long ); + void addWidget( Arts::Widget w, long n ) { addWidget( w,n,0 ); } + void addWidget( Arts::Widget w ) { addWidget( w,0,0 ); } + + void insertWidget( long, Arts::Widget, long, long ); + void insertWidget( long i, Arts::Widget w, long n ) { insertWidget( i,w,n,0 ); } + void insertWidget( long i, Arts::Widget w ) {insertWidget( i,w,0,0 ); } + + void addStretch( long ); + void addStretch() { addStretch( 0 ); } + + void addSpace( long ); + void addStrut( long ); + + void addSeparator( long, long ); + void addSeparator( long ) { addSeparator( 0, 0 ); } + void addSeparator() { addSeparator( 0, 0 ); } + + void addLine( long, long, long, long ); + void addLine( long width, long space, long stretch ) { addLine( width, space, stretch, 0 ); } + void addLine( long width, long space ) { addLine( width, space, 0, 0 ); } + + long spacing(); + void spacing( long ); + + long layoutmargin(); + void layoutmargin( long ); +}; // class + +} // namespace + +class KDE_EXPORT KLayoutBox_Separator : public QWidget { + Q_OBJECT +public: + KLayoutBox_Separator( QWidget*, const char* =0 ); + void resizeEvent( QResizeEvent* ); + void paintEvent( QPaintEvent* ); + QSize minimumSizeHint() const; +}; + +class KLayoutBox_Line : public QWidget { + Q_OBJECT +private: + int _width, _space; +public: + KLayoutBox_Line( int, int, QWidget*, const char* =0 ); + void paintEvent( QPaintEvent* ); + QSize minimumSizeHint() const; +}; + +#endif + +// vim: sw=4 ts=4 + diff --git a/arts/gui/kde/klevelmeter_firebars.cpp b/arts/gui/kde/klevelmeter_firebars.cpp new file mode 100644 index 00000000..916c6b53 --- /dev/null +++ b/arts/gui/kde/klevelmeter_firebars.cpp @@ -0,0 +1,125 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 "klevelmeter_firebars.h" + +#include +#include +#include + +KLevelMeter_FireBars_private::KLevelMeter_FireBars_private( KLevelMeter_FireBars* p, const char* n ) : QWidget( p,n ) { + _parent = p; + _pixmap = new QPixmap( 0,0 ); +// setPaletteBackgroundColor( QColor( 0,0,255 ) ); +} +void KLevelMeter_FireBars_private::paintEvent( QPaintEvent* ) { + QPainter p; + if ( _pixmap->size() != this->size() ) { + _pixmap->resize( this->size() ); + p.begin( _pixmap ); + _pixmap->fill( paletteBackgroundColor() ); + if ( dir==Arts::BottomToTop || dir==Arts::TopToBottom ) { +kdDebug() << k_funcinfo << dir << endl; + //if ( dir==Arts::BottomToTop ) p.translate( 0, rect().bottom() ); + for ( int i=this->height(); i>0; i-- ) { + p.setPen( _parent->color( 1-float( i )/this->height() ) ); + //if ( dir==Arts::BottomToTop ) i *= -1; + p.drawLine( 0, i, this->width(), i ); + } + } else { + if ( dir==Arts::RightToLeft ) p.translate( 0, rect().right() ); + for ( int i=this->width(); i>0; i-- ) { + p.setPen( _parent->color( float( i )/this->width() ) ); + if ( dir==Arts::RightToLeft ) i *= -1; + p.drawLine( i, 0, i, this->height() ); + } + } + p.end(); + } + p.begin( this ); + p.translate( 0,0 ); + p.drawPixmap( QPoint( 0,0 ), *_pixmap ); + p.end(); +} + +KLevelMeter_FireBars::KLevelMeter_FireBars( Arts::KLevelMeter_impl* impl, QWidget* parent, long substyle, long count, Arts::Direction dir, float _dbmin, float _dbmax ) : KLevelMeter_Template( impl, parent, substyle, count, dir, _dbmin, _dbmax ) { +//kdDebug()<<"KLevelMeter_FireBars::KLevelMeter_FireBars( Arts::KLevelMeter_impl* "<setMinimumSize( 5, 5 ); + _bar = new KLevelMeter_FireBars_private( this, 0 ); + _peakwidget = new QWidget( this ); + _peakwidget->resize( size() ); + _peakwidget->setPaletteBackgroundColor( color( 1 ) ); + _peakwidget->hide(); +} + +void KLevelMeter_FireBars::invalue( float n, float p ) { +//kdDebug()<<"KLevelMeter_FireBars::invalue( float n )"<size() != this->size() ) _peakwidget->setGeometry( 0,0, size().width(), size().height() ); + _value = amptondb( n ); + _peak = amptondb( p ); + if ( _peak > 1 )_peakwidget->show(); else _peakwidget->hide(); + _bar->dir = _dir; + switch ( _dir ) { + default: + case Arts::BottomToTop: + _bar->setGeometry( 0, int( this->height()-_value*this->height() ), this->width(), this->height() ); + break; + case Arts::TopToBottom: + _bar->setGeometry( 0, -int( this->height()-_value*this->height() ), this->width(), this->height() ); + break; + case Arts::LeftToRight: + _bar->setGeometry( -int( this->width()-_value*this->width() ), 0, this->width(), this->height() ); + break; + case Arts::RightToLeft: + _bar->setGeometry( int( this->width()-_value*this->width() ), 0, this->width(), this->height() ); + break; + } + repaint(); +} + +void KLevelMeter_FireBars::paintEvent( QPaintEvent* ) { + QPainter p( this ); + //p.setPen( NoPen ); + p.setPen( QColor( 0,0,255 ) ); + // PeakBar + if ( _peak > 1.0/1000 ) { + if ( _dir == Arts::BottomToTop || _dir == Arts::TopToBottom ) { + if ( _dir == Arts::BottomToTop ) p.translate( 0, rect().bottom() ); + int h = int( this->height()*_peak ); + if ( _dir==Arts::BottomToTop ) h *= -1; + p.drawLine( 0, h, this->width(), h ); + } else { + if ( _dir==Arts::RightToLeft ) p.translate( 0, rect().right() ); + int w = int( this->width()* _peak ); + if ( _dir==Arts::RightToLeft ) w *= -1; + p.drawLine( w, 0, w, this->height() ); + } + } +} + +/** + Planned feature: a little Tooltip showing the actual value of the volume in deziBel and perhaps as linear scaleFactor +*/ +void KLevelMeter_FireBars::mouseMoveEvent( QMouseEvent* /*qme*/ ) { +//kdDebug()<<"KLevelMeter_FireBars::mouseMoveEvent(QMouseEvent* "< +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klevelmeter_firebars.h b/arts/gui/kde/klevelmeter_firebars.h new file mode 100644 index 00000000..49ffa75a --- /dev/null +++ b/arts/gui/kde/klevelmeter_firebars.h @@ -0,0 +1,58 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_KLEVELMETER_FIREBARS_H +#define ARTS_KLEVELMETER_FIREBARS_H + +#include "klevelmeter_template.h" + +class QPixmap; +class KLevelMeter_FireBars; + +class KLevelMeter_FireBars_private : public QWidget { + Q_OBJECT +public: + KLevelMeter_FireBars_private( KLevelMeter_FireBars*, const char* ); + void paintEvent( QPaintEvent* ); + + Arts::Direction dir; +private: + KLevelMeter_FireBars* _parent; + QPixmap *_pixmap; +}; + +class KLevelMeter_FireBars : public KLevelMeter_Template { + Q_OBJECT +public: + KLevelMeter_FireBars( Arts::KLevelMeter_impl*, QWidget* =0, long substyle=0, long count=0, Arts::Direction =Arts::BottomToTop, float _dbmin=-24, float _dbmax=6 ); + + void invalue( float, float =0 ); + + void paintEvent( QPaintEvent* ); + + void mouseMoveEvent( QMouseEvent* ); +private: + float _value, _peak; + KLevelMeter_FireBars_private *_bar; + QWidget* _peakwidget; +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klevelmeter_impl.cpp b/arts/gui/kde/klevelmeter_impl.cpp new file mode 100644 index 00000000..ff04edde --- /dev/null +++ b/arts/gui/kde/klevelmeter_impl.cpp @@ -0,0 +1,131 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 "klevelmeter_impl.h" + +#include + +#include +#include +#include +#include + +#include "klevelmeter_private.h" +#include "klevelmeter_private.moc" +#include "klevelmeter_template.h" +#include "klevelmeter_template.moc" + +#include "klevelmeter_small.h" +#include "klevelmeter_linebars.h" +#include "klevelmeter_firebars.h" +#include "klevelmeter_normalbars.h" + +using namespace Arts; +using namespace std; + +KLevelMeter_Private::KLevelMeter_Private( KLevelMeter_impl* impl, QFrame* frame, LevelMeterStyle defstyle, QObject* parent, const char* name ) + : QObject( parent, name ) + , _impl( impl ) + , _frame( frame ) + , _levelmeter( 0 ) + , _style( defstyle ) + , _substyle( 0 ) + , _count( 20 ) + , _direction( Arts::BottomToTop ) + , _peak( 20 ), _peakvalue( 0.0 ) + , _dbmin( -36 ), _dbmax( 0 ) +{ + _layout = new QBoxLayout( _frame, QBoxLayout::LeftToRight ); +} + +void KLevelMeter_Private::createWidget() { + if ( _levelmeter != 0 ) { _levelmeter->hide(); delete _levelmeter; _levelmeter=0; } + switch ( _style ) { + case lmNormalBars: + _levelmeter = new KLevelMeter_NormalBars( _impl, _frame, _substyle, _count, _direction, _dbmin, _dbmax ); + break; + case lmFireBars: + _levelmeter = new KLevelMeter_FireBars( _impl, _frame, _substyle, _count, _direction, _dbmin, _dbmax ); + break; + default: + case lmLineBars: + _levelmeter = new KLevelMeter_LineBars( _impl, _frame, _substyle, _count, _direction, _dbmin, _dbmax ); + break; + case lmSmall: + _levelmeter = new KLevelMeter_Small( _impl, _frame, _substyle, _count, _direction, _dbmin, _dbmax ); + break; + } + _layout->addWidget( _levelmeter ); + _levelmeter->show(); + _levelmeter->setMinimumSize( 10,10 ); +} + +KLevelMeter_impl::KLevelMeter_impl( QFrame* w ) : Arts::KFrame_impl( w ? w : new QFrame( 0 ) ) { +//kdDebug()<<"KLevelMeter_impl::KLevelMeter_impl( QFrame* "<createWidget(); +} + +LevelMeterStyle KLevelMeter_impl::style() { return p->_style; } + +void KLevelMeter_impl::style( LevelMeterStyle style ) { + if ( p->_style!=style ) + { + p->_style = style; + p->createWidget(); + } +} + +long KLevelMeter_impl::substyle() { return p->_substyle; } +void KLevelMeter_impl::substyle( long n ) { p->_substyle = n; p->_levelmeter->substyle( n ); } + +long KLevelMeter_impl::count() { return p->_levelmeter->count(); } +void KLevelMeter_impl::count( long n ) { p->_levelmeter->count( n ); p->_count = n; } + +long KLevelMeter_impl::peakfalloff() { return p->_peak; } +void KLevelMeter_impl::peakfalloff( long n ) { p->_peak = n; } + +float KLevelMeter_impl::mindB() { return p->_levelmeter->dbmin; } +void KLevelMeter_impl::mindB( float n ) { p->_levelmeter->dbmin = n; p->_dbmin = n; } +float KLevelMeter_impl::maxdB() { return p->_levelmeter->dbmax; } +void KLevelMeter_impl::maxdB( float n ) { p->_levelmeter->dbmax = n; p->_dbmax = n; } + +float KLevelMeter_impl::invalue() { return 0.0; } +void KLevelMeter_impl::invalue( float n ) { +//kdDebug()<<"KLevelMeter_impl::invalue( float n="<_peak ) { + p->_peakvalue = ( p->_peak*p->_peakvalue + n ) / ( p->_peak + 1 ); + if ( p->_peakvalue < n ) p->_peakvalue = n; + } + else p->_peakvalue = 0.0; + p->_levelmeter->invalue( n, p->_peakvalue ); +} + +Arts::Direction KLevelMeter_impl::direction() { return p->_direction; } +void KLevelMeter_impl::direction( Arts::Direction n ) { + p->_direction = n; + p->_levelmeter->direction( n ); +} + +REGISTER_IMPLEMENTATION( KLevelMeter_impl ); + +// vim: sw=4 ts=4 + diff --git a/arts/gui/kde/klevelmeter_impl.h b/arts/gui/kde/klevelmeter_impl.h new file mode 100644 index 00000000..53dc5fe2 --- /dev/null +++ b/arts/gui/kde/klevelmeter_impl.h @@ -0,0 +1,70 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_KLEVELMETER_IMPL_H +#define ARTS_KLEVELMETER_IMPL_H + +#include "artsgui.h" + +#include "kframe_impl.h" + +class QFrame; + +class KLevelMeter_Private; + +namespace Arts { // namespace Arts + +class KLevelMeter_impl : virtual public Arts::LevelMeter_skel, + virtual public Arts::KFrame_impl +{ +private: + KLevelMeter_Private *p; +public: + KLevelMeter_impl( QFrame* =0 ); + + LevelMeterStyle style(); + void style( LevelMeterStyle ); + + long substyle(); + void substyle( long ); + + long count(); + void count( long ); + + long peakfalloff(); + void peakfalloff( long ); + + float mindB(); + void mindB( float ); + float maxdB(); + void maxdB( float ); + + float invalue(); + void invalue( float ); + + Arts::Direction direction(); + void direction( Arts::Direction ); +}; //class KLevelMeter_impl + +} // namespace Arts + +#endif +// vim: sw=4 ts=4 + diff --git a/arts/gui/kde/klevelmeter_linebars.cpp b/arts/gui/kde/klevelmeter_linebars.cpp new file mode 100644 index 00000000..108c5a94 --- /dev/null +++ b/arts/gui/kde/klevelmeter_linebars.cpp @@ -0,0 +1,109 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 "klevelmeter_linebars.h" + +#include +#include +#include + +KLevelMeter_LineBars::KLevelMeter_LineBars( Arts::KLevelMeter_impl* impl, QWidget* parent, long substyle, long count, Arts::Direction dir, float _dbmin, float _dbmax ) : KLevelMeter_Template( impl, parent, substyle, count, dir, _dbmin, _dbmax ) + , _value( 0.0 ) + , _peak( 0.0 ) +{ +//kdDebug()<<"KLevelMeter_LineBars::KLevelMeter_LineBars( Arts::KLevelMeter_impl* "<setMinimumSize( 5, 5 ); + this->substyle( substyle ); + _stdcolors = colorGroup(); + setBackgroundMode( Qt::NoBackground ); +} + +void KLevelMeter_LineBars::invalue( float n, float p ) { + _value = amptondb( n ); + _peak = amptondb( p ); + repaint(); +} + +void KLevelMeter_LineBars::substyle( long n ) { + //kdDebug() << k_funcinfo << n << endl; + _substyle = n; +} +long KLevelMeter_LineBars::substyle() { return _substyle; } + +void KLevelMeter_LineBars::paintEvent( QPaintEvent* ) { + QPixmap pm( size() ); + QPainter p( &pm ); + + switch ( _dir ) { + case Arts::BottomToTop: + break; + case Arts::TopToBottom: + p.rotate( 180.0 ); + p.translate( -width() + 1, -height() + 1 ); + break; + case Arts::LeftToRight: + p.rotate( 90.0 ); + p.translate( 0, -width() + 1 ); + break; + case Arts::RightToLeft: + p.rotate( 270.0 ); + p.translate( -height() + 1, 0 ); + break; + } + + if ( _substyle & 1 ) + p.setBrush( ( _peak<1 )?QColor( 0,0,255 ):QColor( 255,0,0 ) ); + else + p.setBrush( ( _peak<1 )?color( _value ):QColor( 255,0,0 ) ); + + QColor bgcolor = ( _substyle & 2 ) ? p.brush().color().dark() : _stdcolors.background(); + pm.fill( bgcolor ); + + p.setPen( NoPen ); + + QSize s = size(); + if ( Arts::LeftToRight == _dir || Arts::RightToLeft == _dir ) + s.transpose(); + + // Value + int h = int( s.height() * _value ); + int top = s.height() - h; + int w = s.width(); + p.drawRect( 0, top, w, h ); + // PeakBar + if ( _peak > 1.0/1000 && _peak <= 1.0 ) { + p.setPen( QColor( 255-bgcolor.red(), 255-bgcolor.green(), 255-bgcolor.blue() ) ); + top = int( s.height() * ( 1 - _peak ) ); + p.drawLine( 0, top, w, top ); + } + + bitBlt( this, 0, 0, &pm, 0, 0, pm.width(), pm.height(), CopyROP, true ); +} + +/** + Planned feature: a little Tooltip showing the actual value of the volume in deziBel and perhaps as linear scaleFactor +*/ +void KLevelMeter_LineBars::mouseMoveEvent( QMouseEvent* /*qme*/ ) { +//kdDebug()<<"KLevelMeter_LineBars::mouseMoveEvent(QMouseEvent* "< + + 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; + version 2 of the License. + + 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 "klevelmeter_normalbars.h" + +#include +#include +#include + +KLevelMeter_NormalBars::KLevelMeter_NormalBars( Arts::KLevelMeter_impl* impl, QWidget* parent, long substyle, long count, Arts::Direction dir, float _dbmin, float _dbmax ) : KLevelMeter_Template( impl, parent, substyle, count, dir, _dbmin, _dbmax ) { +//kdDebug()<<"KLevelMeter_NormalBars::KLevelMeter_NormalBars( Arts::KLevelMeter_impl* "<direction() ) ) _layout->setDirection( QBoxLayout::Direction( _dir ) ); + for ( uint i=0; isetValue( _value ); +} + +long KLevelMeter_NormalBars::count() { return _count; } +void KLevelMeter_NormalBars::count( long n ) { +//kdDebug()<<"KLevelMeter_NormalBars::count( long "<0 ) { + _count = n; + resizeEvent(); + } +} + +void KLevelMeter_NormalBars::resizeEvent( QResizeEvent* ) { + //kdDebug()<<"KLevelMeter_NormalBars::resizeEvent( QResizeEvent* )"< + +class Bar; +class QBoxLayout; + +class KLevelMeter_NormalBars : public KLevelMeter_Template { + Q_OBJECT +public: + KLevelMeter_NormalBars( Arts::KLevelMeter_impl*, QWidget* =0, long substyle=0, long count=25, Arts::Direction =Arts::BottomToTop, float _dbmin=-24, float _dbmax=6 ); + + void invalue( float, float =0 ); + + void count( long ); + long count(); + + void resizeEvent( QResizeEvent* =0 ); +private: + float _value, _peak; + QPtrList bars; +// long _count; + QBoxLayout *_layout; +}; + +class Bar : public QWidget { + Q_OBJECT +private: + float _min, _max; + QColor _color; + bool _on; +public: + Bar( float min, float max, QColor color, QWidget* parent ) : QWidget( parent ), _min( min ), _max( max ), _color( color ), _on( false ) { + setBackgroundColor( _color.dark() ); + } + void setValue( float n ) { + if ( n>_min /*&& n<_max*/ ) on( true ); + else on( false ); + } + void on( bool n ) { + if ( _on != n ) + { + _on = n; + if ( _on ) setBackgroundColor( _color ); + else setBackgroundColor( _color.dark() ); + } + } + void setValues( float min, float max, QColor color ) { _min = min; _max = max; _color = color; on( _on ); } +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klevelmeter_private.h b/arts/gui/kde/klevelmeter_private.h new file mode 100644 index 00000000..c1826c63 --- /dev/null +++ b/arts/gui/kde/klevelmeter_private.h @@ -0,0 +1,55 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_KLEVELMETER_PRIVATE_H +#define ARTS_KLEVELMETER_PRIVATE_H + +#include + +#include "klevelmeter_impl.h" + +class KLevelMeter_Template; +class QBoxLayout; +class KArtsWidget; + +class KLevelMeter_Private : public QObject { + Q_OBJECT +public: + Arts::KLevelMeter_impl* _impl; + QFrame* _frame; + QBoxLayout *_layout; + + KLevelMeter_Template *_levelmeter; + + Arts::LevelMeterStyle _style; + long _substyle; + long _count; + Arts::Direction _direction; + long _peak; + float _peakvalue; + float _dbmin, _dbmax; + + KLevelMeter_Private( Arts::KLevelMeter_impl* impl, QFrame* frame, Arts::LevelMeterStyle defstyle, QObject* =0, const char* =0 ); + + void createWidget(); +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klevelmeter_small.cpp b/arts/gui/kde/klevelmeter_small.cpp new file mode 100644 index 00000000..94ba0df0 --- /dev/null +++ b/arts/gui/kde/klevelmeter_small.cpp @@ -0,0 +1,59 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 "klevelmeter_small.h" + +#include +#include + +KLevelMeter_Small::KLevelMeter_Small( Arts::KLevelMeter_impl* impl, QWidget* parent, long substyle, long count, Arts::Direction dir, float _dbmin, float _dbmax ) : KLevelMeter_Template( impl, parent, substyle, count, dir, _dbmin, _dbmax ) { +//kdDebug()<<"KLevelMeter_Small::KLevelMeter_Small( Arts::KLevelMeter_impl* "<setBackgroundColor( color( amptondb( n ) ) ); + else this->setBackgroundColor( QColor( 0,255,0 ).dark() ); +} + +void KLevelMeter_Small::paintEvent( QPaintEvent* /*qpe*/ ) { +//kdDebug()<<"KLevelMeter_Small::paintEvent( QPaintEvent* "<paletteBackgroundColor(); + p.setPen( QColor( 255-bgcolor.red(), 255-bgcolor.green(), 255-bgcolor.blue() ) ); + if ( _dir==Arts::BottomToTop || _dir==Arts::TopToBottom ) { + if ( _dir==Arts::BottomToTop ) p.translate( 0, rect().bottom() ); + int h = int( this->height() * _peak ); + if ( _dir==Arts::BottomToTop ) h *= -1; + p.drawLine( 0, h, this->width(), h ); + } else { + if ( _dir==Arts::RightToLeft ) p.translate( 0, rect().right() ); + int w = int( this->width() * _peak ); + if ( _dir==Arts::RightToLeft ) w *= -1; + p.drawLine( w, 0, w, this->height() ); + } + } +} + +#include +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klevelmeter_small.h b/arts/gui/kde/klevelmeter_small.h new file mode 100644 index 00000000..837c2bf6 --- /dev/null +++ b/arts/gui/kde/klevelmeter_small.h @@ -0,0 +1,39 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_KLEVELMETER_SMALL_H +#define ARTS_KLEVELMETER_SMALL_H + +#include "klevelmeter_template.h" + +class KLevelMeter_Small : public KLevelMeter_Template { + Q_OBJECT +public: + KLevelMeter_Small( Arts::KLevelMeter_impl*, QWidget* =0, long substyle=0, long count=0, Arts::Direction =Arts::BottomToTop, float _dbmin=-24, float _dbmax=6 ); + + void invalue( float, float =0 ); + + void paintEvent( QPaintEvent* ); +private: + float _peak; +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klevelmeter_template.h b/arts/gui/kde/klevelmeter_template.h new file mode 100644 index 00000000..f1557d28 --- /dev/null +++ b/arts/gui/kde/klevelmeter_template.h @@ -0,0 +1,70 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_KLEVELMETER_TEMPLATE_H +#define ARTS_KLEVELMETER_TEMPLATE_H + +#include + +#include + +#include "dbvolcalc.h" + +#include "klevelmeter_impl.h" + +class KLevelMeter_Template : public QWidget, public dB2VolCalc { + Q_OBJECT +public: + Arts::KLevelMeter_impl* _impl; + + KLevelMeter_Template( Arts::KLevelMeter_impl* impl, QWidget* p, long /*substyle*/, long count, Arts::Direction dir, float _dbmin, float _dbmax ) + : QWidget( p ) + , dB2VolCalc( _dbmin, _dbmax ) + , _impl( impl ) + , _count( count ) + , nilline( 3/4.0 ) + , _dir( dir ) + {} + + virtual void invalue( float, float =0 ) =0; + + virtual void substyle( long ) {} + virtual long substyle() { return 0; } + + virtual void count( long ) {} + virtual long count() { return 0; } + long _count; + + void direction( Arts::Direction dir ) { _dir = dir; } + Arts::Direction direction() { return _dir; } + + float nilline; + /// Gives the colors between green and red + QColor color( float n ) { + return QColor( int( ( n<=nilline )?255*( 1/nilline )*n:255 ), + int( ( n<=1 && n>nilline )?255-255*( 1/nilline )*( n-nilline ):( ( n>1 )?0:255 ) ), + 0 ); + } +protected: + Arts::Direction _dir; +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klineedit_impl.cpp b/arts/gui/kde/klineedit_impl.cpp new file mode 100644 index 00000000..473ace81 --- /dev/null +++ b/arts/gui/kde/klineedit_impl.cpp @@ -0,0 +1,75 @@ +/* + Copyright (C) 2000 Stefan Westerfeld + 2001 Charles Samuels + 2002 Matthias Kretz + + 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. + +*/ + +#include "klineedit_impl.h" +#include "klineedit_impl.moc" + +using namespace Arts; +using namespace std; + +KLineEditStringMapper::KLineEditStringMapper(KLineEdit_impl *impl, KLineEdit *ke) + :impl(impl) +{ + connect(ke, SIGNAL(textChanged(const QString&)), + this, SLOT(textChanged(const QString&))); +} + +void KLineEditStringMapper::textChanged(const QString& newText) +{ + impl->textChanged(newText.utf8().data()); +} + +KLineEdit_impl::KLineEdit_impl( KLineEdit * widget ) + : KWidget_impl( widget ? widget : new KLineEdit ) +{ + _klineedit = static_cast( _qwidget ); + ( void )new KLineEditStringMapper( this, _klineedit ); +} + +string KLineEdit_impl::text() +{ + return _klineedit->text().utf8().data(); +} + +void KLineEdit_impl::text(const string& newText) +{ + _klineedit->setText(QString::fromUtf8(newText.c_str())); +} + +void KLineEdit_impl::textChanged(const string& newText) +{ + text_changed(newText); +} + +string KLineEdit_impl::caption() +{ + return ""; // FIXME +} + +void KLineEdit_impl::caption(const string& /*newCaption*/) +{ + // FIXME +} + +REGISTER_IMPLEMENTATION(KLineEdit_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/klineedit_impl.h b/arts/gui/kde/klineedit_impl.h new file mode 100644 index 00000000..a079a2dc --- /dev/null +++ b/arts/gui/kde/klineedit_impl.h @@ -0,0 +1,63 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#ifndef klineedit_impl_h +#define klineedit_impl_h + +#include "kwidget_impl.h" +#include + + +namespace Arts { + +class KLineEdit_impl : virtual public Arts::LineEdit_skel, + public Arts::KWidget_impl +{ +protected: + KLineEdit * _klineedit; + +public: + KLineEdit_impl( KLineEdit * w = 0 ); + void constructor( Widget p ) { parent( p ); } + + std::string caption(); + void caption(const std::string& newCaption); + std::string text(); + void text(const std::string& newText); + void textChanged(const std::string& newText); +}; + +class KLineEditStringMapper :public QObject { + Q_OBJECT + KLineEdit_impl *impl; +public: + KLineEditStringMapper(KLineEdit_impl *impl, KLineEdit *ed); +public slots: + void textChanged(const QString& newText); +}; + +} + +#endif + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kpopupbox_impl.cpp b/arts/gui/kde/kpopupbox_impl.cpp new file mode 100644 index 00000000..03651ea2 --- /dev/null +++ b/arts/gui/kde/kpopupbox_impl.cpp @@ -0,0 +1,134 @@ + /* + + Copyright ( C ) 2002, 2003 Arnold Krille + + 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. + + */ + +#include "kpopupbox_impl.h" +#include "kpopupbox_private.h" + +#include + +using namespace Arts; + +KPopupBox_impl::KPopupBox_impl( KPopupBox_widget *w ) : KFrame_impl( w ? w : new KPopupBox_widget ) +{ + self().framestyle( Box ); self().margin( 1 ); self().linewidth( 1 ); + self().vSizePolicy( spFixed ); self().hSizePolicy( spFixed ); + + if( !w ) w = static_cast( _qframe ); + + _widget = w; +// _mapper = new KPopupBoxEventMapper( _widget, this ); +} +KPopupBox_impl::~KPopupBox_impl() { +} + +Direction KPopupBox_impl::direction() { return _widget->direction(); } +void KPopupBox_impl::direction( Direction n ) { _widget->direction( n ); } + +void KPopupBox_impl::widget( Arts::Widget widget ) { + widget.parent( self() ); + this->_addChild( widget, "PopupBox_child" ); + _widget->setWidget( widget ); +} +Arts::Widget KPopupBox_impl::widget() { return _widget->getWidget(); } + +std::string KPopupBox_impl::name() { return _name; } +void KPopupBox_impl::name( const std::string& n ) { _name = ""; _name = n; _widget->name( n ); } + +// Following the private class: + +KPopupBox_widget::KPopupBox_widget( QWidget *parent, const char* name ) : QFrame( parent,name ) +{ + this->setFrameShape( QFrame::Box ); + this->setMargin( 1 ); this->setLineWidth( 1 ); + + _titlebar = new QFrame( this ); + _titlebarlayout = new QBoxLayout( _titlebar, QBoxLayout::BottomToTop ); + _titlebarlayout->setAutoAdd( true ); + + _showbutton = new ShowButton( _titlebar ); + connect( _showbutton, SIGNAL( toggled( bool ) ), this, SLOT( hide( bool ) ) ); + _drag = new HandleDrag( _titlebar ); + connect( _drag, SIGNAL( clicked() ), _showbutton, SLOT( toggle() ) ); + _ownbutton = new OwnButton( _titlebar ); + connect( _ownbutton, SIGNAL( toggled( bool ) ), this, SLOT( own( bool ) ) ); + + _artswidget = new OwnWidget( _showbutton, this ); + + _layout = new QBoxLayout( this, QBoxLayout::LeftToRight ); + _layout->addWidget( _titlebar , -1 ); + _layout->addWidget( _artswidget, 20 ); + _layout->addStretch( 0 ); +} +KPopupBox_widget::~KPopupBox_widget() { +} + +Arts::Direction KPopupBox_widget::direction() { + return Arts::Direction( _layout->direction() ); +} + +void KPopupBox_widget::direction( Arts::Direction n ) { + _layout->setDirection( QBoxLayout::Direction( n ) ); + _showbutton->direction( QBoxLayout::Direction( n ) ); + switch( n ) { + case LeftToRight: + case RightToLeft: + _titlebarlayout->setDirection( QBoxLayout::BottomToTop ); + _drag->setMinimumHeight( 30 ); + _drag->setMinimumWidth( 0 ); + break; + case TopToBottom: + case BottomToTop: + _titlebarlayout->setDirection( QBoxLayout::RightToLeft ); + _drag->setMinimumHeight( 0 ); + _drag->setMinimumWidth( 30 ); + } +} + +void KPopupBox_widget::setWidget( Arts::Widget widget ) { _artswidget->setContent( widget ); } +Arts::Widget KPopupBox_widget::getWidget() { return _artswidget->content(); } + +void KPopupBox_widget::hide( bool n ) { + if( n ) + _artswidget->hide(); + else + _artswidget->show(); +} + +void KPopupBox_widget::own( bool n ) { + if ( n ) + _artswidget->reparent( 0, _artswidget->mapToGlobal( _artswidget->pos() ), !( _artswidget->isHidden() ) ); + else + { + _artswidget->reparent( this, QPoint( 0,0 ), !( _artswidget->isHidden() ) ); + _layout->insertWidget( 1, _artswidget, 20 ); + } +} + +void KPopupBox_widget::name( std::string n ) { + _artswidget->setCaption( n.c_str() ); +} + +REGISTER_IMPLEMENTATION( KPopupBox_impl ); + +#include "kpopupbox_private.moc" + +// vim: sw=4 ts=4 + diff --git a/arts/gui/kde/kpopupbox_impl.h b/arts/gui/kde/kpopupbox_impl.h new file mode 100644 index 00000000..e3c8c250 --- /dev/null +++ b/arts/gui/kde/kpopupbox_impl.h @@ -0,0 +1,70 @@ + /* + + Copyright ( C ) 2002, 2003 Arnold Krille + + 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. + + */ + +#ifndef KPOPUPBOX_IMPL_H +#define KPOPUPBOX_IMPL_H + +#include +#include + +class QBoxLayout; +class KPopupBox_widget; +//class KPopupBoxEventMapper; // The EventMapper isn't needed at present, but perhaps in the future... + +namespace Arts { + +/// The PopupBox + +class KPopupBox_impl : virtual public Arts::PopupBox_skel, public Arts::KFrame_impl +{ +public: + /// selfreference like 'this' + PopupBox self() { return PopupBox::_from_base( _copy() ); } + /// Constructor + KPopupBox_impl( KPopupBox_widget *w=0 ); + ~KPopupBox_impl(); + + /// The name of the widget + std::string name(); + void name( const std::string & ); + + /// The direction. LeftToRight (true) or TopToBottom (false). May get other values in the future. + Direction direction(); + void direction( Direction ); + + /// Set and Get the Widget. + void widget( Arts::Widget ); + Arts::Widget widget(); + +private: + std::string _name; + bool _lefttoright; + KPopupBox_widget *_widget; +// KPopupBoxEventMapper *_mapper; + +}; // class KPopupBox + +} // namespace Arts + +#endif + +// vim: sw=4 ts=4 + diff --git a/arts/gui/kde/kpopupbox_private.h b/arts/gui/kde/kpopupbox_private.h new file mode 100644 index 00000000..b7e383d1 --- /dev/null +++ b/arts/gui/kde/kpopupbox_private.h @@ -0,0 +1,216 @@ + /* + + Copyright ( C ) 2002, 2003 Arnold Krille + + 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. + + */ + +#ifndef KPOPUPBOX_PRIVATE_H +#define KPOPUPBOX_PRIVATE_H + + +class HandleDrag; +class ShowButton; +class OwnButton; +class KArtsWidget; +class OwnWidget; +class QBoxLayout; + +#include + +class KPopupBox_widget : public QFrame +{ + Q_OBJECT +public: + KPopupBox_widget( QWidget* =0, const char* =0); + ~KPopupBox_widget(); + + Arts::Direction direction(); + void direction( Arts::Direction ); + + void setWidget( Arts::Widget widget ); + Arts::Widget getWidget(); + + void name( std::string ); +private slots: + void hide( bool ); + void own( bool ); +private: + QBoxLayout *_layout; + + QFrame *_titlebar; + QBoxLayout *_titlebarlayout; + HandleDrag *_drag; + ShowButton *_showbutton; + OwnButton *_ownbutton; + + OwnWidget *_artswidget; +}; + +// See kpopupbox_impl.h - The eventmapper isn't needed at present, but perhaps in the future... + +/*class KPopupBoxEventMapper : public QObject { + Q_OBJECT +public: + KPopupBoxEventMapper( KPopupBox_widget *widget, Arts::KPopupBox_impl *impl ) + : QObject( widget,"" ), _widget( widget ), _impl( impl ) + {} +private: + KPopupBox_widget *_widget; + Arts::KPopupBox_impl *_impl; +};*/ + +#include +#include + +class HandleDrag : public QWidget { + Q_OBJECT +public: + HandleDrag( QWidget *parent, const char* name=0 ) : QWidget( parent,name ) {} + void paintEvent( QPaintEvent * ) { + QPainter p( this ); + QStyle::SFlags flags = QStyle::Style_Default; + if( width() < height() ) flags |= QStyle::Style_Horizontal; + style().drawPrimitive( QStyle::PE_DockWindowHandle, &p, rect(), colorGroup(), flags ); + } +signals: + void clicked(); +protected: + virtual void mouseDoubleClickEvent( QMouseEvent * ) { + emit clicked(); + } +}; + +static const char* const close_xpm[] = { "5 5 2 1", "# c black", ". c None", "#...#", ".#.#.", "..#..", ".#.#.", "#...#"}; +static const char* const up_xpm[] = { "5 5 2 1", "# c black", ". c None", ".....", "..#..", ".###.", "#####", "....."}; +static const char* const down_xpm[] = { "5 5 2 1", "# c black", ". c None", ".....", "#####", ".###.", "..#..", "....."}; +static const char* const left_xpm[] = { "5 5 2 1", "# c black", ". c None", "...#.", "..##.", ".###.", "..##.", "...#."}; +static const char* const right_xpm[] = { "5 5 2 1", "# c black", ". c None", ".#...", ".##..", ".###.", ".##..", ".#..."}; +static const char* const inside_xpm[] = { "5 5 2 1", "# c black", ". c None", "#####", "#...#", "#...#", "#...#", "#####"}; +static const char* const own_xpm[] = { "5 5 2 1", "# c black", ". c None", "###..", "#.###", "###.#", ".#..#", ".####"}; + +#include +#include + +class ShowButton : public QPushButton { + Q_OBJECT +private: + QBoxLayout::Direction _dir; + QPixmap _pmleft, _pmright, _pmup, _pmdown; +public: + ShowButton( QWidget *parent, const char* name=0 ) : QPushButton( parent,name ), _dir( QBoxLayout::LeftToRight ) + { + connect( this, SIGNAL( toggled( bool ) ), this, SLOT( owntoggle( bool ) ) ); + setToggleButton( true ); + _pmleft = QPixmap( const_cast( left_xpm ) ); + _pmright = QPixmap( const_cast( right_xpm ) ); + _pmup = QPixmap( const_cast( up_xpm ) ); + _pmdown = QPixmap( const_cast( down_xpm ) ); + setPixmap( _pmright ); + } + + void direction( QBoxLayout::Direction n ) { _dir=n; } +public slots: + void owntoggle( bool b ) { + switch( _dir ) + { + case QBoxLayout::BottomToTop: + if( b ) setPixmap( _pmdown ); + else setPixmap( _pmup ); + break; + case QBoxLayout::TopToBottom: + if( b ) setPixmap( _pmup ); + else setPixmap( _pmdown ); + break; + case QBoxLayout::LeftToRight: + if( b ) setPixmap( _pmright ); + else setPixmap( _pmleft ); + break; + case QBoxLayout::RightToLeft: + if( b ) setPixmap( _pmleft ); + else setPixmap( _pmright ); + break; + } + } +public: + QSize minimumSizeHint() const { + int wh = style().pixelMetric( QStyle::PM_DockWindowHandleExtent, this ); + return QSize( wh, wh ); + } + QSizePolicy sizePolicy() const { return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); } + QSize minimumSize() const { return minimumSizeHint(); } + QSize sizeHint() const { return minimumSize(); } + + void drawButton( QPainter * p ) + { + p->fillRect( 0,0, width(), height(), QBrush( colorGroup().brush( QColorGroup::Background ) ) ); + p->drawPixmap( ( width() - pixmap()->width() ) / 2, ( height() - pixmap()->height() ) / 2, *pixmap() ); + } +}; + +class OwnButton : public QPushButton { + Q_OBJECT +private: + QPixmap _pmown, _pminside; +public: + OwnButton( QWidget *parent, const char* name=0 ) : QPushButton( parent,name ) + { + connect( this, SIGNAL( toggled( bool ) ), this, SLOT( toggle( bool ) ) ); + setToggleButton( true ); + _pmown = QPixmap( const_cast( own_xpm ) ); + _pminside = QPixmap( const_cast( inside_xpm ) ); + setPixmap( _pmown ); + } + +public slots: + void toggle( bool b ) { + if( b ) setPixmap( _pminside ); + else setPixmap( _pmown ); + } +public: + QSize minimumSizeHint() const { + int wh = style().pixelMetric( QStyle::PM_DockWindowHandleExtent, this ); + return QSize( wh, wh ); + } + QSizePolicy sizePolicy() const { return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed ); } + QSize minimumSize() const { return minimumSizeHint(); } + QSize sizeHint() const { return minimumSize(); } + + void drawButton( QPainter * p ) + { + p->fillRect( 0,0, width(), height(), QBrush( colorGroup().brush( QColorGroup::Background ) ) ); + p->drawPixmap( ( width() - pixmap()->width() ) / 2, ( height() - pixmap()->height() ) / 2, *pixmap() ); + } +}; + +#include + +class OwnWidget : public KArtsWidget +{ + Q_OBJECT + ShowButton *_b; +public: + OwnWidget( ShowButton* b, QWidget* p, const char* n=0, WFlags f=0 ) : KArtsWidget( p,n,f ) { _b = b; } + ~OwnWidget() {} +public slots: + void closeEvent( QCloseEvent * ) { _b->toggle(); } +}; + +#endif + +// vim: sw=4 ts=4 + diff --git a/arts/gui/kde/kpoti.cpp b/arts/gui/kde/kpoti.cpp new file mode 100644 index 00000000..e12c1bf5 --- /dev/null +++ b/arts/gui/kde/kpoti.cpp @@ -0,0 +1,780 @@ +/*************************************************************************** + kpoti.cpp - potentiometer widget + ------------------- + begin : Wed Apr 28 23:05:05 MEST 1999 + + copyright : (C) 1999 by Martin Lorenz + email : lorenz@ch.tum.de + (C) 2002-2003 Matthias Kretz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#include "kpoti.h" +#include "kpoti.moc" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include + +#define PI 3.1415926 +static const int thresholdTime = 500; +static const int repeatTime = 100; +static const float maxAngle = PI*135/180; // 140 degrees to both sides +static const float tickLength = 3; + +struct KPoti::KPotiPrivate +{ + KPotiPrivate() + : bgDirty( false ) + , potiDirty( false ) + {} + + bool bgDirty; + KPixmap bgdb; + KPixmap bgPixmap( const QColorGroup & colorGroup ) + { + if( bgDirty || bgdb.isNull() ) + { + bgdb.resize( buttonRect.size() ); + QPainter dbp( &bgdb ); + dbp.setPen( Qt::NoPen ); + QRect drawRect = bgdb.rect(); + + // create mask + QBitmap mask( bgdb.size(), true ); + QPainter maskpainter( &mask ); + maskpainter.setPen( Qt::NoPen ); + maskpainter.setBrush( Qt::color1 ); + maskpainter.drawEllipse( drawRect ); + maskpainter.end(); + bgdb.setMask( mask ); + + // inset shadow + KPixmap gradient( bgdb.size() ); + KPixmapEffect::gradient( gradient, colorGroup.light(), colorGroup.dark(), KPixmapEffect::DiagonalGradient ); + dbp.setBrush( QBrush( colorGroup.button(), gradient ) ); + dbp.drawEllipse( drawRect ); + + potiRect.setSize( drawRect.size() * 0.9 ); + if( potiRect.width() + 6 > drawRect.width() ) + { + potiRect.setWidth( drawRect.width() - 6 ); + potiRect.setHeight( drawRect.height() - 6 ); + } + potiRect.moveCenter( center ); + + bgDirty = false; + } + return bgdb; + } + + QColor potiColor; + bool potiDirty; + KPixmap potidb; + KPixmap potiPixmap() + { + if( ( potiDirty || potidb.isNull() ) && ! potiRect.size().isEmpty() ) + { + potidb.resize( potiRect.size() ); + QPainter dbp( &potidb ); + dbp.setPen( Qt::NoPen ); + QRect drawRect( potidb.rect() ); + + // create mask + QBitmap mask( potidb.size(), true ); + QPainter maskpainter( &mask ); + maskpainter.setPen( Qt::NoPen ); + maskpainter.setBrush( Qt::color1 ); + maskpainter.drawEllipse( drawRect ); + maskpainter.end(); + potidb.setMask( mask ); + + KPixmap gradient( potidb.size() ); + KPixmapEffect::gradient( gradient, potiColor.dark( 130 ), potiColor.light( 130 ), KPixmapEffect::DiagonalGradient ); + dbp.setBrush( QBrush( potiColor, gradient ) ); + dbp.drawEllipse( drawRect ); + + potiDirty = false; + } + return potidb; + } + + QRect buttonRect; + QRect potiRect; + QRect labelRect; + QString label; + QPoint center; +}; + +QSizePolicy KPoti::sizePolicy() const +{ + return QSizePolicy( QSizePolicy::Preferred, QSizePolicy::Preferred ); +} + +QSize KPoti::sizeHint() const +{ + return minimumSizeHint(); +} + +QSize KPoti::minimumSizeHint() const +{ + int width = 40; + int height = 40; + if( m_bLabel ) + { + QFontMetrics metrics( font() ); + d->labelRect = metrics.boundingRect( d->label ); + d->labelRect.setHeight( metrics.lineSpacing() ); + width = KMAX( width, d->labelRect.width() + frameRect().width() - contentsRect().width() ); + height += metrics.lineSpacing(); + } + //kdDebug() << k_funcinfo << "return " << width << "x" << height << endl; + return QSize( width, height ); +} + +QString KPoti::text() const +{ + return d->label; +} + +void KPoti::setText( const QString & text ) +{ + d->label = text; + setMinimumSize( minimumSizeHint() ); + updateGeometry(); +} + +/** + Constructs a poti. + + The \e parent and \e name arguments are sent to the QWidget constructor. +*/ +KPoti::KPoti( QWidget *parent, const char *name ) + : QFrame( parent, name, WResizeNoErase | WRepaintNoErase ) + , d( 0 ) +{ + init(); +} + + + +/** + Constructs a poti. + + \arg \e minValue is the minimum slider value. + \arg \e maxValue is the maximum slider value. + \arg \e step is the page step value. + \arg \e value is the initial value. + + The \e parent and \e name arguments are sent to the QWidget constructor. +*/ + +KPoti::KPoti( int minValue, int maxValue, int step, + int value, QWidget *parent, const char *name ) + : QFrame( parent, name, WResizeNoErase | WRepaintNoErase ) + , QRangeControl( minValue, maxValue, 1, step, value ) + , d( 0 ) +{ + init(value); +} + +KPoti::~KPoti() +{ + delete d; + d = 0; +} + +void KPoti::init(int value) +{ + d = new KPotiPrivate; + font().setPointSize( 8 ); + d->potiColor.setNamedColor( "red" ); + + timer = 0; + potiVal = value; + potiPos = positionFromValue(value); + clickOffset = 0; + state = Idle; + track = TRUE; + ticks = TRUE; + m_bLabel = true; + tickInt = 0; + + setFocusPolicy( TabFocus ); + initTicks(); +} + + +/** + Does what's needed when someone changes the tickmark status +*/ + +void KPoti::initTicks() +{ + QRect available = contentsRect(); + if( m_bLabel ) + available.rTop() += d->labelRect.height(); + d->center = available.center(); + // make the width and height equal + if( available.width() > available.height() ) + available.setWidth( available.height() ); + else if( available.height() > available.width() ) + available.setHeight( available.width() ); + available.moveCenter( d->center ); + d->buttonRect = available; + + buttonRadius = available.width() / 2.0; + if( ticks ) + { + buttonRadius -= tickLength; + int tickSpace = static_cast( tickLength ); + d->buttonRect.rTop() += tickSpace; + d->buttonRect.rLeft() += tickSpace; + d->buttonRect.rRight() -= tickSpace; + d->buttonRect.rBottom() -= tickSpace; + } + + d->potiDirty = true; + d->bgDirty = true; +} + + +/** + Enables slider tracking if \e enable is TRUE, or disables tracking + if \e enable is FALSE. + + If tracking is enabled (default), the slider emits the + valueChanged() signal whenever the slider is being dragged. If + tracking is disabled, the slider emits the valueChanged() signal + when the user releases the mouse button (unless the value happens to + be the same as before). + + \sa tracking() +*/ + +void KPoti::setTracking( bool enable ) +{ + track = enable; +} + + +/** + \fn bool KPoti::tracking() const + Returns TRUE if tracking is enabled, or FALSE if tracking is disabled. + + Tracking is initially enabled. + + \sa setTracking() +*/ + + +/** + \fn void KPoti::valueChanged( int value ) + This signal is emitted when the slider value is changed, with the + new slider value as an argument. +*/ + +/** + \fn void KPoti::sliderPressed() + This signal is emitted when the user presses the slider with the mouse. +*/ + +/** + \fn void KPoti::sliderMoved( int value ) + This signal is emitted when the slider is dragged, with the + new slider value as an argument. +*/ + +/** + \fn void KPoti::sliderReleased() + This signal is emitted when the user releases the slider with the mouse. +*/ + +/** + Calculates slider position corresponding to value \a v. Does not perform + rounding. +*/ + +float KPoti::positionFromValue( int v ) const +{ + + int range = maxValue() - minValue(); + return ( (v - minValue() ) *2* maxAngle) / range - maxAngle; +} + + +/** + Calculates value corresponding to poti position \a p. Performs rounding. +*/ + +int KPoti::valueFromPosition( float p ) const +{ + int range = maxValue() - minValue(); + return (int) (minValue() + ((p+maxAngle)*range)/(2*maxAngle)); +} + +/*! + Implements the virtual QRangeControl function. +*/ + +void KPoti::rangeChange() +{ + float newPos = positionFromValue( value() ); + if ( newPos != potiPos ) { + reallyMovePoti( newPos ); + } +} + +void KPoti::paletteChange( const QPalette & ) +{ + d->bgDirty = true; + d->potiDirty = true; +} + +/*! + Changes the value (slot) +*/ + +void KPoti::valueChange() +{ + if ( potiVal != value() ) { + float newPos = positionFromValue( value() ); + potiVal = value(); + reallyMovePoti( newPos ); + } + emit valueChanged(value()); +} + + +/*! + Handles resize events for the poti. +*/ + +void KPoti::resizeEvent( QResizeEvent * ) +{ + rangeChange(); + initTicks(); +} + +void KPoti::setLabel(bool s) +{ + m_bLabel = s; + initTicks(); +} + +/** + Sets the color of the button + */ +void KPoti::setColor( const QColor &c ) +{ + d->potiColor = c; + d->potiDirty = true; + repaint(); +} + + +void KPoti::paintPoti( QPainter * p ) +{ + if( isVisible() ) + { + KPixmap db = d->potiPixmap(); + if( db.isNull() ) + return; + + QPainter p2( &db ); + p2.translate( db.rect().center().x(), db.rect().center().y() ); + p2.rotate( potiPos * 180.0 / PI ); + QRect pointer( db.width() / -20, db.width() / -2, db.width() / 10, db.width() / 2 ); + QBrush buttonbrush( colorGroup().button() ); + qDrawShadePanel( &p2, pointer, colorGroup(), true, 1, &buttonbrush ); + p2.end(); + + p->drawPixmap( d->potiRect, db ); + } +} + +/*! + Performs the actual moving of the slider. +*/ + +void KPoti::reallyMovePoti( float newPos ) +{ + QPainter p; + p.begin( this ); + p.setPen(NoPen); + potiPos = newPos; + paintPoti(&p); + p.end(); +} + + + + +/** + Handles paint events for the slider. +*/ + +void KPoti::drawContents( QPainter * p ) +{ + QPixmap doublebuffer( contentsRect().size() ); + doublebuffer.fill( colorGroup().background() ); + QPainter dbp( &doublebuffer ); + if( m_bLabel ) + { + dbp.setFont( font() ); + QFontMetrics metrics = dbp.fontMetrics(); + dbp.drawText( contentsRect().x() - metrics.leftBearing( d->label[ 0 ] ) + ( contentsRect().width() - d->labelRect.width() ) / 2, metrics.height(), d->label ); + } + + int interval = tickInt; + if( interval <= 0 ) + interval = 12; + if( ticks ) + drawTicks( &dbp, buttonRadius, tickLength, interval ); + + dbp.drawPixmap( d->buttonRect, d->bgPixmap( colorGroup() ) ); + + if( hasFocus() ) + style().drawPrimitive( QStyle::PE_FocusRect, &dbp, d->buttonRect, colorGroup() ); + + paintPoti( &dbp ); + dbp.end(); + p->drawPixmap( contentsRect(), doublebuffer ); +} + + +/*! + Handles mouse press events for the slider. +*/ + +void KPoti::mousePressEvent( QMouseEvent *e ) +{ + resetState(); + + if ( e->button() == MidButton ) { + double pos = atan2( double(e->pos().x()-d->center.x()), + double(- e->pos().y() + d->center.y()) ); + movePoti( pos ); + return; + } + if ( e->button() != LeftButton ) + return; + + + int dx=e->pos().x()-d->center.x(), dy=e->pos().y()-d->center.y(); + + if ( dx*dx+dy*dy < buttonRadius*buttonRadius ) { + state = Dragging; + clickOffset = potiVal + (e->pos().y() ) ; + emit potiPressed(); + } else if ( e->pos().x() < width()/2 ) { + state = TimingDown; + subtractPage(); + if ( !timer ) + timer = new QTimer( this ); + connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout()) ); + timer->start( thresholdTime, TRUE ); + } else { + state = TimingUp; + addPage(); + if ( !timer ) + timer = new QTimer( this ); + connect( timer, SIGNAL(timeout()), SLOT(repeatTimeout()) ); + timer->start( thresholdTime, TRUE ); + } +} + +/*! + Handles mouse move events for the slider. +*/ +void KPoti::mouseMoveEvent( QMouseEvent *e ) +{ + + if ( (e->state() & MidButton) ) { // middle button wins + double pos = atan2( double(e->pos().x()-d->center.x()), + double(- e->pos().y()+d->center.y()) ); + movePoti( pos ); + return; + } + if ( !(e->state() & LeftButton) ) + return; // left mouse button is up + if ( state != Dragging ) + return; + + + movePoti( positionFromValue(- e->pos().y() + clickOffset )); +} + + +/*! + Handles mouse release events for the slider. +*/ + +void KPoti::mouseReleaseEvent( QMouseEvent *e ) +{ + if ( !(e->button() & LeftButton) ) + return; + resetState(); +} + +void KPoti::focusInEvent( QFocusEvent * e ) +{ + //setFrameStyle( Raised | Box ); + //setLineWidth( 1 ); + QFrame::focusInEvent( e ); +} + +void KPoti::focusOutEvent( QFocusEvent * e ) +{ + //setFrameStyle( NoFrame ); + //setLineWidth( 0 ); + QFrame::focusOutEvent( e ); +} + + +void KPoti::enterEvent( QEvent * ) +{ + emit mouseEntered( potiVal ); +} + + +/*! + Moves the left (or top) edge of the slider to position + \a pos. Performs snapping. +*/ + +void KPoti::movePoti( float pos ) +{ + float newPos = QMIN( maxAngle, QMAX( -maxAngle, pos ) ); + int newVal = valueFromPosition( newPos ); + if ( potiVal != newVal ) { + potiVal = newVal; + emit potiMoved( potiVal ); + } + if ( tracking() && potiVal != value() ) { + directSetValue( potiVal ); + emit valueChanged( potiVal ); + } + + + if ( potiPos != newPos ) + reallyMovePoti( newPos ); +} + + +/*! + Resets all state information and stops my timer. +*/ + +void KPoti::resetState() +{ + if ( timer ) { + timer->stop(); + timer->disconnect(); + } + switch ( state ) { + case TimingUp: + case TimingDown: + break; + case Dragging: { + setValue( valueFromPosition( potiPos ) ); + emit potiReleased(); + break; + } + case Idle: + break; + default: + kdWarning() << "KPoti: in wrong state" << endl; + } + state = Idle; +} + + +/*! + Handles key press events for the slider. +*/ + +void KPoti::keyPressEvent( QKeyEvent *e ) +{ + + switch ( e->key() ) { + case Key_Left: + subtractLine(); + break; + case Key_Right: + addLine(); + break; + case Key_Up: + addLine(); + break; + case Key_Down: + subtractLine(); + break; + case Key_Prior: + subtractPage(); + break; + case Key_Next: + addPage(); + break; + case Key_Home: + setValue( minValue() ); + break; + case Key_End: + setValue( maxValue() ); + break; + default: + e->ignore(); + return; + } + e->accept(); +} + + + + + +/*! + Makes QRangeControl::setValue() available as a slot. +*/ + +void KPoti::setValue( int value ) +{ + QRangeControl::setValue( value ); +} + + +/*! + Moves the slider one pageStep() upwards. +*/ + +void KPoti::addStep() +{ + addPage(); +} + + +/*! + Moves the slider one pageStep() downwards. +*/ + +void KPoti::subtractStep() +{ + subtractPage(); +} + + +/*! + Waits for autorepeat. +*/ + +void KPoti::repeatTimeout() +{ + Q_ASSERT( timer ); + timer->disconnect(); + if ( state == TimingDown ) + connect( timer, SIGNAL(timeout()), SLOT(subtractStep()) ); + else if ( state == TimingUp ) + connect( timer, SIGNAL(timeout()), SLOT(addStep()) ); + timer->start( repeatTime, FALSE ); +} + + + + +/*! + Using \a p, draws tickmarks at a distance of \a dist from the edge + of the widget, using \a w pixels and \a i intervals. + */ + +void KPoti::drawTicks( QPainter *p, double dist, double w, int i ) const +{ + p->setPen( colorGroup().foreground() ); + double angle,s,c; + double x, y; + for (int v=0; v<=i; v++) + { + angle = -maxAngle+2*maxAngle*v/i; + s = sin( angle ); + c = cos( angle ); + x = d->center.x() - s * dist; + y = d->center.y() - c * dist; + + p->drawLine( (int)x, (int)y, (int)(x - s * w), (int)(y - c * w) ); + } +} + +void KPoti::wheelEvent(QWheelEvent *e) +{ + setValue(value()+e->delta()/120*8); +} + + +/*! + Sets the way tickmarks are displayed by the slider. \a s can take + the following values: +
    +
  • \c NoMarks +
  • \c Above +
  • \c Left +
  • \c Below +
  • \c Right +
  • \c Both +
+ The initial value is \c NoMarks. + \sa tickmarks(), setTickInterval() +*/ + +void KPoti::setTickmarks( bool s ) +{ + ticks = s; + initTicks(); + update(); +} + + + +/*! + Sets the interval between tickmarks to \a i. This is a value interval, + not a pixel interval. If \a i is 0, the slider + will choose between lineStep() and pageStep(). The initial value of + tickInterval() is 0. + \sa tickInterval(), QRangeControl::lineStep(), QRangeControl::pageStep() +*/ + +void KPoti::setTickInterval( int i ) +{ + tickInt = QMAX( 0, i ); + update(); +} + + +/*! + \fn int KPoti::tickInterval() const + Returns the interval between tickmarks. Returns 0 if the slider + chooses between pageStep() and lineStep(). + \sa setTickInterval() +*/ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kpoti.h b/arts/gui/kde/kpoti.h new file mode 100644 index 00000000..a87b5162 --- /dev/null +++ b/arts/gui/kde/kpoti.h @@ -0,0 +1,136 @@ +/*************************************************************************** + kpoti.h - Potentiometer Widget + ------------------- + begin : Wed Apr 28 23:05:05 MEST 1999 + + copyright : (C) 1999 by Martin Lorenz + email : lorenz@ch.tum.de + (C) 2002 Matthias Kretz + ***************************************************************************/ + +/*************************************************************************** + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + ***************************************************************************/ + +#ifndef _KPOTI_H +#define _KPOTI_H + +#include +#include + + +class QTimer; +struct QPotiData; + + +class KPoti : public QFrame, public QRangeControl +{ + Q_OBJECT +public: + + KPoti( QWidget *parent=0, const char *name=0 ); + KPoti( int minValue, int maxValue, int step, int value, + QWidget *parent=0, const char *name=0 ); + + ~KPoti(); + + void setTracking( bool enable ); + bool tracking() const; + + void setColor( const QColor & ); + + virtual void setTickmarks( bool ); + virtual void setLabel( bool ); + bool tickmarks() const { return ticks; } + + virtual void setTickInterval( int ); + int tickInterval() const { return tickInt; } + + virtual QSizePolicy sizePolicy() const; + virtual QSize sizeHint() const; + virtual QSize minimumSizeHint() const; + QString text() const; + +public slots: + void setValue( int ); + void addStep(); + void subtractStep(); + void setText( const QString & ); + +signals: + void valueChanged( int value ); + void potiPressed(); + void potiMoved( int value ); + void potiReleased(); + void mouseEntered(int value); + +protected: + void resizeEvent( QResizeEvent * ); + void drawContents( QPainter * ); + + void keyPressEvent( QKeyEvent * ); + + void mousePressEvent( QMouseEvent * ); + void mouseReleaseEvent( QMouseEvent * ); + void mouseMoveEvent( QMouseEvent * ); + void enterEvent( QEvent *); + + void focusInEvent( QFocusEvent *e ); + void focusOutEvent( QFocusEvent *e ); + + void valueChange(); + void rangeChange(); + + virtual void paletteChange( const QPalette & ); + + virtual void paintPoti( QPainter * ); + void drawButton( QPainter *); + void drawTicks( QPainter *, double, double, int=1 ) const; + + virtual void wheelEvent(QWheelEvent *e); +private slots: + void repeatTimeout(); + +private: + enum State { Idle, Dragging, TimingUp, TimingDown }; + + void init(int value=0); + float positionFromValue( int ) const; + int valueFromPosition( float ) const; + void movePoti( float ); + void reallyMovePoti( float ); + void resetState(); + int potiRadius() const; + void initTicks(); + + QTimer *timer; + float potiPos; + int potiVal; + int clickOffset; + State state; + bool track; + bool ticks, m_bLabel; + int tickInt, space; + double buttonRadius; +private: // Disabled copy constructor and operator= + // KPoti( const KPoti & ) {} + //KPoti &operator=( const KPoti & ) { return *this; } + struct KPotiPrivate; + KPotiPrivate * d; +}; + +inline bool KPoti::tracking() const +{ + return track; +} + + +#endif // _KPOTI_H + + + diff --git a/arts/gui/kde/kpoti_impl.cpp b/arts/gui/kde/kpoti_impl.cpp new file mode 100644 index 00000000..10b0adb3 --- /dev/null +++ b/arts/gui/kde/kpoti_impl.cpp @@ -0,0 +1,203 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + + 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. + + */ + +#include "kpoti_impl.h" +#include "kpoti_impl.moc" +#include "anyref.h" +#include "stdio.h" + +#include + +using namespace Arts; +using namespace std; + +PotiIntMapper::PotiIntMapper(KPoti_impl *impl, KPoti *kp) + : QObject( kp ) + , impl( impl ) +{ + connect(kp, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int))); +} + +void PotiIntMapper::valueChanged(int pos) +{ + impl->valueChanged(pos); +} + +KPoti_impl::KPoti_impl( KPoti * widget ) + : KFrame_impl( widget ? widget : new KPoti( 0, 100, 1, 0 ) ) +{ + _min = 0; _max = 1; _value = 0; + _factor = 1; + _logarithmic = 0; + _range = 100; + + _kpoti = static_cast( _qwidget ); + ( void )new PotiIntMapper( this, _kpoti ); +} + +string KPoti_impl::caption() +{ + return _kpoti->text().utf8().data(); +} + +void KPoti_impl::caption(const string& newText) +{ + _caption = QString::fromUtf8( newText.c_str() ); + _kpoti->setText( _caption ); +} + +string KPoti_impl::color() +{ + return _color; +} + +void KPoti_impl::color(const string& newColor) +{ + _color = newColor; + if(strlen(_color.c_str())) + { + QColor qc(_color.c_str()); + _kpoti->setColor(qc); + } +} + +float KPoti_impl::min() +{ + return _min; +} + +void KPoti_impl::min(float newMin) +{ + if(_min != newMin) + { + _min = newMin; + applyValue(); + } +} + +float KPoti_impl::max() +{ + return _max; +} + +void KPoti_impl::max(float newMax) +{ + if(_max != newMax) + { + _max = newMax; + applyValue(); + } +} + +float KPoti_impl::value() +{ + float ret = float(_kpoti->value()) / _factor; + if(_logarithmic > 0) + ret = convertFromLog(ret); + if(ret < _min) + ret = _min; + else if(ret > _max) + ret = _max; + return ret; +} + +void KPoti_impl::value(float newValue) +{ + if(newValue != _value) + { + _value = newValue; + applyValue(); + if(visible()) + value_changed(value()); + } +} + +long KPoti_impl::range() +{ + return _range; +} + +void KPoti_impl::range(long newRange) +{ + if(_range != newRange) + { + _range = newRange; + applyValue(); + } +} + +void KPoti_impl::valueChanged(int newvalue) +{ + _value = (float)newvalue / _factor; + if(_logarithmic > 0) + _value = convertFromLog(_value); + if(visible()) + value_changed(value()); +} + +float KPoti_impl::convertToLog(float val) +{ + return log(val) / log(_logarithmic); +} + +float KPoti_impl::convertFromLog(float val) +{ + return pow(_logarithmic, val); +} + +void KPoti_impl::applyValue() +{ + double dmin = _min; + double dmax = _max; + double dvalue = _value; + if(_logarithmic > 0) + { + dmin = convertToLog(_min); + dmax = convertToLog(_max); + dvalue = convertToLog(_value); + } + _factor = _range / (dmax - dmin); + int imin = int(_factor * dmin); + int imax = int(_factor * dmax); + int ivalue = int(_factor * dvalue); + _kpoti->setRange(imin, imax); + _kpoti->setValue(ivalue); +} + +void KPoti_impl::logarithmic(float newLogarithmic) +{ + if(_logarithmic != newLogarithmic) + { + _logarithmic = newLogarithmic; + applyValue(); + } +} + +float KPoti_impl::logarithmic() +{ + return _logarithmic; +} + +REGISTER_IMPLEMENTATION(KPoti_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kpoti_impl.h b/arts/gui/kde/kpoti_impl.h new file mode 100644 index 00000000..94b03a6f --- /dev/null +++ b/arts/gui/kde/kpoti_impl.h @@ -0,0 +1,90 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2001, 2002 Matthias Kretz + + 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. + + */ + +#ifndef ARTS_GUI_KPOTI_IMPL_H +#define ARTS_GUI_KPOTI_IMPL_H +#include "kframe_impl.h" +#include "kpoti.h" + +#include +#include + + +namespace Arts { + +class KPoti_impl; + +class PotiIntMapper :public QObject { + Q_OBJECT + KPoti_impl *impl; +public: + PotiIntMapper(KPoti_impl *impl, KPoti *kp); +public slots: + void valueChanged(int x); +}; + +class KPoti_impl : virtual public Arts::Poti_skel, + public Arts::KFrame_impl +{ +protected: + KPoti * _kpoti; + QString _caption; + std::string _color; + float _min, _max, _value; + float _factor; + float _logarithmic; + long _range; + + float convertToLog(float); + float convertFromLog(float); + void applyValue(); + +public: + KPoti_impl( KPoti * w = 0 ); + + std::string caption(); + void caption(const std::string& newText); + std::string color(); + void color(const std::string& newColor); + + float logarithmic(); + void logarithmic(float); + + float min(); + void min(float newMin); + float max(); + void max(float newMax); + float value(); + void value(float newValue); + + long range(); + void range(long newRange); + + /* from qt */ + void valueChanged(int newValue); +}; + +} +#endif /* ARTS_GUI_KPOTI_IMPL_H */ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kspinbox_impl.cpp b/arts/gui/kde/kspinbox_impl.cpp new file mode 100644 index 00000000..f97716c4 --- /dev/null +++ b/arts/gui/kde/kspinbox_impl.cpp @@ -0,0 +1,108 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#include "kspinbox_impl.h" +#include "kspinbox_impl.moc" +#include "anyref.h" +#include "stdio.h" + +using namespace Arts; +using namespace std; + +SpinBoxIntMapper::SpinBoxIntMapper(KSpinBox_impl *impl, QSpinBox *sp) + :impl(impl) +{ + connect(sp, SIGNAL(valueChanged(int)), this, SLOT(valueChanged(int))); +} + +void SpinBoxIntMapper::valueChanged(int pos) +{ + impl->valueChanged(pos); +} + +KSpinBox_impl::KSpinBox_impl( QSpinBox * widget ) + : KWidget_impl( widget ? widget : new QSpinBox ) +{ + _min = 0; _max = 100; _value = 0; + _qspinbox = static_cast( _qwidget ); + _qspinbox->setRange( 0, 100 ); + ( void )new SpinBoxIntMapper( this, _qspinbox ); +} + +string KSpinBox_impl::caption() +{ + return _caption.utf8().data(); +} + +void KSpinBox_impl::caption(const string& newCaption) +{ + _caption = QString::fromUtf8(newCaption.c_str()); + // FIXME: do something with the caption here +} + +long KSpinBox_impl::min() +{ + return _min; +} + +void KSpinBox_impl::min(long newMin) +{ + _min = newMin; + _qspinbox->setMinValue(newMin); +} + +long KSpinBox_impl::max() +{ + return _max; +} + +void KSpinBox_impl::max(long newMax) +{ + _max = newMax; + _qspinbox->setMaxValue(newMax); +} + +long KSpinBox_impl::value() +{ + return _value; +} + +void KSpinBox_impl::value(long newValue) +{ + if(newValue != _value) + { + _value = newValue; + _qspinbox->setValue(newValue); + if(visible()) + value_changed(newValue); + } +} + +void KSpinBox_impl::valueChanged(int newvalue) +{ + value(newvalue); +} + +REGISTER_IMPLEMENTATION(KSpinBox_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kspinbox_impl.h b/arts/gui/kde/kspinbox_impl.h new file mode 100644 index 00000000..b0af8bae --- /dev/null +++ b/arts/gui/kde/kspinbox_impl.h @@ -0,0 +1,76 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#ifndef ARTS_GUI_KSPINBOX_IMPL_H +#define ARTS_GUI_KSPINBOX_IMPL_H +#include "kwidget_impl.h" + +#include +#include +#include + + +namespace Arts { + +class KSpinBox_impl; +class SpinBoxIntMapper :public QObject { + Q_OBJECT + KSpinBox_impl *impl; +public: + SpinBoxIntMapper(KSpinBox_impl *impl, QSpinBox *sp); +public slots: + void valueChanged(int x); +}; + +class KSpinBox_impl : virtual public Arts::SpinBox_skel, + public Arts::KWidget_impl +{ +protected: + QSpinBox * _qspinbox; + QString _caption; + long _min, _max, _value; + + void applyValue(); + +public: + KSpinBox_impl( QSpinBox * w = 0 ); + void constructor( Widget p ) { parent( p ); } + + std::string caption(); + void caption(const std::string& newCaption); + + long min(); + void min(long newMin); + long max(); + void max(long newMax); + long value(); + void value(long newValue); + + /* from qt */ + void valueChanged(int newValue); +}; + +} +#endif /* ARTS_GUI_KSPINBOX_IMPL_H */ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/ktickmarks_impl.cpp b/arts/gui/kde/ktickmarks_impl.cpp new file mode 100644 index 00000000..0aa0a01e --- /dev/null +++ b/arts/gui/kde/ktickmarks_impl.cpp @@ -0,0 +1,179 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 "ktickmarks_impl.h" + +#include +#include +#include +#include + +KTickmarks_impl::KTickmarks_impl( QFrame* w ) : Arts::KFrame_impl( w ? w : new KTickmarks_Widget( 0 ) ) +{ + //kdDebug()<<"KTickmarks_impl::KTickmarks_impl( QFrame* w="<( _qwidget ); +} + +float KTickmarks_impl::min() { return _tmwidget->dbmin; } +void KTickmarks_impl::min( float n ) { _tmwidget->dbmin = n; } +float KTickmarks_impl::max() { return _tmwidget->dbmax; } +void KTickmarks_impl::max( float n ) { _tmwidget->dbmax = n; } +float KTickmarks_impl::minstep() { return _tmwidget->minstep; } +void KTickmarks_impl::minstep( float n ) { _tmwidget->minstep = n; } +float KTickmarks_impl::substep() { return _tmwidget->substep; } +void KTickmarks_impl::substep( float n ) { _tmwidget->substep = n; } + +Arts::Direction KTickmarks_impl::direction() { return _tmwidget->_dir; } +void KTickmarks_impl::direction( Arts::Direction n ) { _tmwidget->_dir = n; } + +long KTickmarks_impl::position() { return _tmwidget->_pos; } +void KTickmarks_impl::position( long n ) { _tmwidget->_pos = n; } + +void KTickmarks_impl::constructor( float min, float max, Arts::Direction dir, long pos ) { + this->min( min ); this->max( max ); direction( dir ); position( pos ); +} + +KTickmarks_Widget::KTickmarks_Widget( KTickmarks_impl* impl, QWidget* p, const char* n ) : QFrame( p,n ), dB2VolCalc( -24, 0 ), _impl( impl ), _pos( Arts::posLeft ), _dir( Arts::BottomToTop ), minstep( 1 ), substep( 0.5 ) { + setMinimumSize( 20,20 ); +} + +void KTickmarks_Widget::drawContents( QPainter* p ) { + //kdDebug()<<"KTickmarks::drawContents( QPainter* "<setFont( font ); + // Determining the size of the largest text (currently the text at the minimum-scale) + QFontMetrics fontmetric( font ); + QRect fontrect = fontmetric.boundingRect( QString::number( dbmin ) ); + // Calculating stepsizes + float _minstepcount = ( dbmax-dbmin )/minstep; + float _minstep = minstep; // this value gets changed + float _substepcount = ( dbmax-dbmin )/substep; + float _substep = substep; // this value gets changed + // Calculating minimum size of the widget + int _minsize; + // Shorcuts + int w,h; + QColor colornormal = colorGroup().foreground(); + QColor colordiff = colorGroup().buttonText(); + + if ( _dir == Arts::BottomToTop || _dir == Arts::TopToBottom ) { + p->translate( contentsRect().left(), contentsRect().bottom() ); + // Calculating stepsizes + for ( int i=1; _minstepcount*( fontrect.height()+4 ) > contentsRect().height(); i++ ) { + _minstepcount = ( dbmax-dbmin ) / minstep / i; + _minstep = minstep*i; + } + while ( _substepcount*2 > contentsRect().height() ) { _substepcount/=2; _substep*=2; } + // Calculating minimum size of the widget + _minsize=fontrect.width()+4; + if ( left ) _minsize+=6; + if ( right ) _minsize+=6; + setMinimumWidth( _minsize + frameWidth() + 2 ); +// setMaximumWidth( _minsize /*+6*/ ); + w = contentsRect().width(); // Just a shortcut + h=0; + // Painting substep marks + p->setPen( QPen( colordiff, 1 ) ); + for ( float i=dbmax; i>=dbmin; i-=_substep ) { + h = int( -contentsRect().height() * dbtondb( i ) ); + if ( _dir==Arts::TopToBottom ) h = 1 - h; + if ( left ) p->drawLine( 0, h, 3, h ); + if ( right ) p->drawLine( w-3, h, w, h ); + } + // Painting step marks and texts + p->setPen( QPen( colornormal, 1 ) ); + for ( float i=0; i>=dbmin; i-=_minstep ) { + h = int( -contentsRect().height() * dbtondb( i ) ); + if ( _dir==Arts::TopToBottom ) h = 1 - h; + if ( left ) p->drawLine( 0, h, 6, h ); + p->drawText( ( w - (left)*6 - (right)*6 - fontrect.width() )/2 + (left)*6 + , h-fontrect.height()/2, + fontrect.width(), fontrect.height()+2, + Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); + if ( right ) p->drawLine( w-6, h, w, h ); + } + for ( float i=_minstep; i<=dbmax; i+=_minstep ) { + h = int( -contentsRect().height() * dbtondb( i ) ); + if ( _dir==Arts::TopToBottom ) h = 1 - h; + if ( left ) p->drawLine( 0, h, 6, h ); + p->drawText( ( w - (left)*6 - (right)*6 - fontrect.width() )/2 + (left)*6 + , h-fontrect.height()/2, + fontrect.width(), fontrect.height()+2, + Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); + if ( right ) p->drawLine( w-6, h, w, h ); + } + } else { + //if ( _dir == Arts::LeftToRight || _dir == Arts::RightToLeft ) { + // Calculating stepsizes + for ( int i=1; _minstepcount*( fontrect.width()+4 ) > contentsRect().width(); i++ ) { + _minstepcount = ( dbmax-dbmin ) / minstep / i; + _minstep = minstep*i; + } + while ( _substepcount*2 > contentsRect().width() ) { _substepcount/=2; _substep*=2; } + // Calculating minimum size of the widget + _minsize=fontrect.height()+4; + if ( left ) _minsize+=6; + if ( right ) _minsize+=6; + setMinimumHeight( _minsize + frameWidth() + 2 ); +// setMaximumHeight( _minsize /*+6*/ ); + w = 0; // Just a shortcut + h = frameWidth() + contentsRect().height(); + // Painting substep marks + p->setPen( QPen( colordiff, 1 ) ); + for ( float i=dbmax; i>=dbmin; i-=_substep ) { + w = this->frameWidth()+ int( contentsRect().width() * dbtondb( i ) ); + if ( _dir==Arts::RightToLeft ) w = 1 - w; + if ( left ) p->drawLine( w, frameWidth(), w, frameWidth() + 3 ); + if ( right ) p->drawLine( w, h-3, w, h ); + } + // Painting step marks and texts + p->setPen( QPen( colornormal, 1 ) ); + for ( float i=0; i>=dbmin; i-=_minstep ) { + w = int( contentsRect().width() * dbtondb( i ) ); + if ( _dir==Arts::RightToLeft ) w = 1 - w; + if ( left ) p->drawLine( w, 0, w, 6 ); + p->drawText( w - fontrect.width()/2 + , ( h - (left)*6 - (right)*6 - fontrect.height() )/2 + (left)*6, + fontrect.width(), fontrect.height()+2, + Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); + if ( right ) p->drawLine( w, h-6, w, h ); + } + for ( float i=_minstep; i<=dbmax; i+=_minstep ) { + h = int( -contentsRect().height() * dbtondb( i ) ); + if ( _dir==Arts::RightToLeft ) w = 1 - w; + if ( left ) p->drawLine( w, 0, w, 6 ); + p->drawText( w - fontrect.width()/2 + , ( h - (left)*6 - (right)*6 - fontrect.height() )/2 + (left)*6, + fontrect.width(), fontrect.height()+2, + Qt::AlignRight|Qt::AlignTop, QString::number( i ) ); + if ( right ) p->drawLine( w, h-6, w, h ); + } + } +} + +REGISTER_IMPLEMENTATION( KTickmarks_impl ); + +#include "ktickmarks_impl.moc" +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/ktickmarks_impl.h b/arts/gui/kde/ktickmarks_impl.h new file mode 100644 index 00000000..5974cf0f --- /dev/null +++ b/arts/gui/kde/ktickmarks_impl.h @@ -0,0 +1,76 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_KLEVELMETER_TICKMARKS_H +#define ARTS_KLEVELMETER_TICKMARKS_H + +#include +#include + +#include "artsgui.h" + +#include "kframe_impl.h" + +#include + +class KTickmarks_Widget; + +class KTickmarks_impl : virtual public Arts::Tickmarks_skel, + virtual public Arts::KFrame_impl +{ +public: + KTickmarks_impl( QFrame* =0 ); + + float min(); + void min( float ); + float max(); + void max( float ); + + float minstep(); + void minstep( float ); + float substep(); + void substep( float ); + + Arts::Direction direction(); + void direction( Arts::Direction ); + + long position(); + void position( long ); + + void constructor( float min, float max, Arts::Direction, long ); +private: + KTickmarks_Widget* _tmwidget; +}; + +class KTickmarks_Widget : public QFrame, public dB2VolCalc { + Q_OBJECT +private: + KTickmarks_impl* _impl; +public: + KTickmarks_Widget( KTickmarks_impl*, QWidget* =0, const char* =0 ); + void drawContents( QPainter* ); + long _pos; + Arts::Direction _dir; + + float minstep, substep; +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kvbox_impl.cpp b/arts/gui/kde/kvbox_impl.cpp new file mode 100644 index 00000000..0b737e78 --- /dev/null +++ b/arts/gui/kde/kvbox_impl.cpp @@ -0,0 +1,51 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#include "kvbox_impl.h" +#include + +using namespace Arts; + +KVBox_impl::KVBox_impl( QVBox * widget ) + : KFrame_impl( widget ? widget : new QVBox ) + , _spacing( 5 ) +{ + _qvbox = static_cast( _qwidget ); + _qvbox->setSpacing( _spacing ); + _qvbox->setMargin( 5 ); +} + +long KVBox_impl::spacing() +{ + return _spacing; +} + +void KVBox_impl::spacing( long s ) +{ + _spacing = s; + _qvbox->setSpacing( s ); +} + +REGISTER_IMPLEMENTATION(KVBox_impl); + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kvbox_impl.h b/arts/gui/kde/kvbox_impl.h new file mode 100644 index 00000000..9358d90e --- /dev/null +++ b/arts/gui/kde/kvbox_impl.h @@ -0,0 +1,48 @@ + /* + + Copyright (C) 2000,2001 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#include "kframe_impl.h" + +class QVBox; + +namespace Arts { + +class KVBox_impl : virtual public Arts::VBox_skel, + public Arts::KFrame_impl +{ +private: + long _spacing; + +protected: + QVBox * _qvbox; + +public: + KVBox_impl( QVBox * w = 0 ); + + long spacing(); + void spacing( long ); +}; + +} + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kvolumefader_impl.cpp b/arts/gui/kde/kvolumefader_impl.cpp new file mode 100644 index 00000000..f3d09a0b --- /dev/null +++ b/arts/gui/kde/kvolumefader_impl.cpp @@ -0,0 +1,243 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 "kvolumefader_impl.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +KVolumeFader_impl::KVolumeFader_impl( QFrame* w ) + : Arts::KFrame_impl( w ? w : new KVolumeFader_Widget( 0 ) ) + , dB2VolCalc( -36, 6 ) + , _dir( Arts::BottomToTop ) + , dbmin_inupdate( false ) + , dbmax_inupdate( false ) + , direction_inupdate( false ) + , ignoreUpdates( 0 ) +{ + //kdDebug()<<"KVolumeFader_impl::KVolumeFader_impl( QFrame* w="<( _qwidget ); + _vfwidget->setImpl( this ); +} + +KVolumeFader_impl::~KVolumeFader_impl() { +} + +float KVolumeFader_impl::dbmin() { return dB2VolCalc::dbmin; } +void KVolumeFader_impl::dbmin( float n ) { + if ( n != dB2VolCalc::dbmin && !dbmin_inupdate ) { + dbmin_inupdate = true; + dB2VolCalc::dbmin = n; + dbmin_changed( dbmin() ); + dbmin_inupdate = false; + } +} +float KVolumeFader_impl::dbmax() { return dB2VolCalc::dbmax; } +void KVolumeFader_impl::dbmax( float n ) { + if ( n != dB2VolCalc::dbmax && !dbmax_inupdate ) { + dbmax_inupdate = true; + dB2VolCalc::dbmax = n; + dbmax_changed( dbmax() ); + dbmax_inupdate = false; + } +} + +Arts::Direction KVolumeFader_impl::direction() { return _dir; } +void KVolumeFader_impl::direction( Arts::Direction n ) { + if ( n != _dir && !direction_inupdate ) { + direction_inupdate = true; + _dir = n; + _vfwidget->setDirection( _dir ); +// direction_changed( direction() ); + direction_inupdate = false; + } +} + +float KVolumeFader_impl::volume() { return _volume; } +void KVolumeFader_impl::volume( float n ) { + //kdDebug() << k_funcinfo << n << " ignore: " << ignoreUpdates << endl; + if ( ignoreUpdates > 0 ) { + --ignoreUpdates; + return; + } + _volume = n; + _vfwidget->setValue( amptondb( _volume ) ); +} + +float KVolumeFader_impl::dbvolume() { return amptodb( _volume ); } +void KVolumeFader_impl::dbvolume( float n ) { + //kdDebug() << k_funcinfo << n << endl; + normalizedvolume( dbtondb( n ) ); +} + +void KVolumeFader_impl::normalizedvolume( float n ) { + if ( ( ndbtodb( n ) > dbmin() ) && ( ndbtodb( n ) < dbmax() ) ) { + float amp = ndbtoamp( n ); + if ( amp != _volume ) { + ++ignoreUpdates; + //kdDebug() << k_funcinfo << ignoreUpdates << endl; + _volume = amp; + _vfwidget->setValue( n ); + volume_changed( _volume ); + } + } +} + +void KVolumeFader_impl::constructor( float dbmin, float dbmax, Arts::Direction dir ) { + this->dbmin( dbmin ); this->dbmax( dbmax ); direction( dir ); +} + + + +KVolumeFader_Widget::KVolumeFader_Widget( QWidget* p, const char* n ) + : QFrame( p,n ) + , _impl( 0 ) + , _inupdate( false ) + , _value( -1 ) + , _dir( Arts::BottomToTop ) + , _menu( new KPopupMenu( this ) ) + , _aExactValue( new KAction( i18n( "Set Exact Value..." ), KShortcut(), this, SLOT( exactValue() ), this ) ) +{ + //kdDebug() << k_funcinfo << endl; + setMinimumSize( 10,10 ); + _aExactValue->plug( _menu ); +} + +void KVolumeFader_Widget::setImpl( KVolumeFader_impl* n ) { _impl = n; update(); } + +KVolumeFader_Widget::~KVolumeFader_Widget() { + //kdDebug() << k_funcinfo << endl; +} + +void KVolumeFader_Widget::setDirection( Arts::Direction n ) { _dir = n; update(); } + +void KVolumeFader_Widget::setValue( float n ) { + //kdDebug() << k_funcinfo << n << endl; + if ( n != _value ) { + _value = n; + update(); + } +} + +QColor KVolumeFader_Widget::interpolate( QColor low, QColor high, float percent ) { + if ( percent<=0 ) return low; else + if ( percent>=1 ) return high; else + return QColor( + int( low.red() + ( high.red()-low.red() ) * percent ), + int( low.green() + ( high.green()-low.green() ) * percent ), + int( low.blue() + ( high.blue()-low.blue() ) * percent ) ); +} + +void KVolumeFader_Widget::drawContents( QPainter* p ){ + if ( _dir==Arts::BottomToTop || _dir==Arts::BottomToTop ) { + float h; + if ( _dir==Arts::BottomToTop ) h = contentsRect().height() * ( 1 - _value ); + else h = contentsRect().height() * _value; + for ( int i=int( h ); isetPen( interpolate( colorGroup().light(), colorGroup().highlight(), float( i )/contentsRect().height() ) ); + p->drawLine( contentsRect().left(), this->frameWidth() + i, contentsRect().right(), this->frameWidth() + i ); + } + p->setPen( colorGroup().dark() ); + p->drawLine( contentsRect().left(), this->frameWidth() + int( h ), contentsRect().right(), this->frameWidth() + int( h ) ); + } else { + float w; + p->translate( this->width(),0 ); + if ( _dir==Arts::LeftToRight ) w = - contentsRect().width() * ( 1 - _value ); + else w = - contentsRect().width() * _value; + for ( int i=int( w ); i>=-contentsRect().width(); i-- ) { + p->setPen( interpolate( colorGroup().light(), colorGroup().highlight(), float( -i )/contentsRect().width() ) ); + p->drawLine( this->frameWidth() + i, contentsRect().top(), this->frameWidth() + i, contentsRect().bottom() ); + } + p->setPen( colorGroup().dark() ); + p->drawLine( this->frameWidth() + int( w ), contentsRect().top(), this->frameWidth() + int( w ), contentsRect().bottom() ); + } +} + +void KVolumeFader_Widget::mousePressEvent( QMouseEvent* ){ + //kdDebug() << k_funcinfo << endl; +} + +void KVolumeFader_Widget::mouseReleaseEvent( QMouseEvent* qme ){ + bool setValue = false; + if ( KGlobalSettings::mouseSettings().handed == 0 && qme->button() == Qt::LeftButton ) setValue=true; + if ( KGlobalSettings::mouseSettings().handed == 1 && qme->button() == Qt::RightButton ) setValue=true; + if ( setValue ) + { + switch ( _dir ) { + default: + case Arts::BottomToTop: + if ( _impl ) _impl->normalizedvolume( 1 - float( qme->y() ) / contentsRect().height() ); + break; + case Arts::TopToBottom: + if ( _impl ) _impl->normalizedvolume( float( qme->y() ) / contentsRect().height() ); + break; + case Arts::LeftToRight: + if ( _impl ) _impl->normalizedvolume( float( qme->x() ) / contentsRect().width() ); + break; + case Arts::RightToLeft: + if ( _impl ) _impl->normalizedvolume( 1 - float( qme->x() ) / contentsRect().width() ); + break; + } + } else _menu->exec( qme->globalPos() ); +} + +void KVolumeFader_Widget::mouseMoveEvent( QMouseEvent* qme ){ + switch ( _dir ) { + default: + case Arts::BottomToTop: + if ( _impl ) _impl->normalizedvolume( 1 - float( qme->y() ) / contentsRect().height() ); + break; + case Arts::TopToBottom: + if ( _impl ) _impl->normalizedvolume( float( qme->y() ) / contentsRect().height() ); + break; + case Arts::LeftToRight: + if ( _impl ) _impl->normalizedvolume( float( qme->x() ) / contentsRect().width() ); + break; + case Arts::RightToLeft: + if ( _impl ) _impl->normalizedvolume( 1 - float( qme->x() ) / contentsRect().width() ); + break; + } +} + +void KVolumeFader_Widget::wheelEvent( QWheelEvent* qwe ){ + //kdDebug() << k_funcinfo << endl; + if ( qwe->delta() < 0 ) { if ( _impl ) _impl->normalizedvolume( _impl->dbtondb( _impl->dbvolume() - 1 ) ); } + if ( qwe->delta() > 0 ) { if ( _impl ) _impl->normalizedvolume( _impl->dbtondb( _impl->dbvolume() + 1 ) ); } +} + +void KVolumeFader_Widget::exactValue() { + //kdDebug() << k_funcinfo << endl; + bool ok=false; + double n = KInputDialog::getDouble( i18n( "Set Exact Volume Value" ), i18n( "Exact volume (dB):" ), _impl->dbvolume(), _impl->dbmin(), _impl->dbmax(), 1, &ok, this ); + if ( ok ) _impl->dbvolume( n ); +} + +REGISTER_IMPLEMENTATION( KVolumeFader_impl ); + +#include "kvolumefader_impl.moc" +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kvolumefader_impl.h b/arts/gui/kde/kvolumefader_impl.h new file mode 100644 index 00000000..31ac438b --- /dev/null +++ b/arts/gui/kde/kvolumefader_impl.h @@ -0,0 +1,97 @@ +/* + Copyright ( C ) 2003 Arnold Krille + + 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; + version 2 of the License. + + 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 ARTS_KVOLUMEFADER_TICKMARKS_H +#define ARTS_KVOLUMEFADER_TICKMARKS_H + +#include +#include + +#include "artsgui.h" + +#include "kframe_impl.h" + +#include + +class KVolumeFader_Widget; + +class KVolumeFader_impl : virtual public Arts::VolumeFader_skel, + virtual public Arts::KFrame_impl, + public dB2VolCalc +{ +public: + KVolumeFader_impl( QFrame* =0 ); + ~KVolumeFader_impl(); + + float dbmin(); + void dbmin( float ); + float dbmax(); + void dbmax( float ); + + Arts::Direction direction(); + void direction( Arts::Direction ); + + float volume(); + void volume( float ); + float dbvolume(); + void dbvolume( float ); + + void normalizedvolume( float ); + + void constructor( float min, float max, Arts::Direction dir ); +private: + KVolumeFader_Widget* _vfwidget; + Arts::Direction _dir; + bool dbmin_inupdate, dbmax_inupdate, direction_inupdate; + float _min, _max, _volume; + int ignoreUpdates; +}; + +class KPopupMenu; +class KAction; + +class KVolumeFader_Widget : public QFrame { + Q_OBJECT +private: + KVolumeFader_impl* _impl; + bool _inupdate; + float _value; + Arts::Direction _dir; + KPopupMenu *_menu; + KAction *_aExactValue; + QColor interpolate( QColor, QColor, float ); +public: + KVolumeFader_Widget( QWidget* =0, const char* =0 ); + ~KVolumeFader_Widget(); + void setImpl( KVolumeFader_impl* ); + void setValue( float ); + void setDirection( Arts::Direction ); +protected: + void drawContents( QPainter* ); + void mousePressEvent( QMouseEvent* ); + void mouseReleaseEvent( QMouseEvent* ); + void mouseMoveEvent( QMouseEvent* ); + void wheelEvent( QWheelEvent* ); +private slots: + void exactValue(); +}; + +#endif +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kwidget_impl.cpp b/arts/gui/kde/kwidget_impl.cpp new file mode 100644 index 00000000..261cf30b --- /dev/null +++ b/arts/gui/kde/kwidget_impl.cpp @@ -0,0 +1,181 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#include "kwidget_impl.h" +#include "kwidgetrepo.h" +#include "debug.h" +#include + +using namespace Arts; + +KWidget_impl::KWidget_impl( QWidget * widget ) + : _qwidget( widget ? widget : new QWidget ) +{ + _widgetID = KWidgetRepo::the()->add( this, _qwidget ); + + /* + * KWidgetGuard will protect us against deleting the widget if Qt already + * has done so (for instance if our widget was inside a panel, and + * the panel got deleted, our widget will be gone, too) + */ + _guard = new KWidgetGuard(this); + QObject::connect(_qwidget, SIGNAL(destroyed()), + _guard, SLOT(widgetDestroyed())); +} + +KWidget_impl::~KWidget_impl() +{ + if(_qwidget) + { + delete _qwidget; + arts_assert(_qwidget == 0); // should be true due to KWidgetGuard + } + delete _guard; +} + +void KWidget_impl::widgetDestroyed() +{ + KWidgetRepo::the()->remove(_widgetID); + _widgetID = 0; + _qwidget = 0; +} + +long KWidget_impl::widgetID() +{ + return _widgetID; +} + +Widget KWidget_impl::parent() +{ + return KWidgetRepo::the()->lookupWidget(_parentID); +} + +void KWidget_impl::parent(Arts::Widget newParent) +{ + if(!newParent.isNull()) + { + _parentID = newParent.widgetID(); + + QWidget *qparent; + qparent = KWidgetRepo::the()->lookupQWidget(newParent.widgetID()); + if( qparent != 0 ) + { + QPoint pos(x(),y()); + bool showIt = visible(); + _qwidget->reparent(qparent, pos, showIt); + } + } + else + { + _parentID = 0; + } +} + +long KWidget_impl::x() +{ + return _qwidget->x(); +} + +void KWidget_impl::x(long newX) +{ + _qwidget->move(newX,y()); +} + +long KWidget_impl::y() +{ + return _qwidget->y(); +} + +void KWidget_impl::y(long newY) +{ + _qwidget->move(x(),newY); +} + +long KWidget_impl::width() +{ + return _qwidget->width(); +} + +void KWidget_impl::width(long newWidth) +{ + _qwidget->resize(newWidth,height()); +} + +long KWidget_impl::height() +{ + return _qwidget->height(); +} + +void KWidget_impl::height(long newHeight) +{ + _qwidget->resize(width(),newHeight); +} + +bool KWidget_impl::visible() +{ + return _qwidget->isVisible(); +} + +void KWidget_impl::visible(bool newVisible) +{ + if(newVisible) show(); else hide(); +} + +SizePolicy KWidget_impl::hSizePolicy() +{ + return ( SizePolicy )_qwidget->sizePolicy().horData(); +} + +void KWidget_impl::hSizePolicy( SizePolicy p ) +{ + QSizePolicy sp = _qwidget->sizePolicy(); + sp.setHorData( ( QSizePolicy::SizeType )p ); + _qwidget->setSizePolicy( sp ); +} + +SizePolicy KWidget_impl::vSizePolicy() +{ + return ( SizePolicy )_qwidget->sizePolicy().verData(); +} + +void KWidget_impl::vSizePolicy( SizePolicy p ) +{ + QSizePolicy sp = _qwidget->sizePolicy(); + sp.setVerData( ( QSizePolicy::SizeType )p ); + _qwidget->setSizePolicy( sp ); +} + +void KWidget_impl::show() +{ + _qwidget->show(); +} + +void KWidget_impl::hide() +{ + _qwidget->hide(); +} + +REGISTER_IMPLEMENTATION(KWidget_impl); +#include "kwidget_impl.moc" + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kwidget_impl.h b/arts/gui/kde/kwidget_impl.h new file mode 100644 index 00000000..b94f1a8d --- /dev/null +++ b/arts/gui/kde/kwidget_impl.h @@ -0,0 +1,88 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + 2002 Matthias Kretz + + 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. + + */ + +#ifndef ARTS_GUI_KWIDGET_IMPL_H +#define ARTS_GUI_KWIDGET_IMPL_H +#include "artsgui.h" +#include +#include +#include + +namespace Arts { + +class KWidgetGuard; +class KDE_EXPORT KWidget_impl : virtual public Arts::Widget_skel { +protected: + QWidget * _qwidget; + KWidgetGuard * _guard; + long _parentID; + long _widgetID; +public: + KWidget_impl( QWidget * w = 0 ); + + ~KWidget_impl(); + + long widgetID(); + Widget parent(); + void parent(Arts::Widget); + long x(); + void x(long newX); + long y(); + void y(long newY); + long width(); + void width(long newWidth); + long height(); + void height(long newHeight); + + bool visible(); + void visible(bool newVisible); + + SizePolicy hSizePolicy(); + void hSizePolicy( SizePolicy ); + SizePolicy vSizePolicy(); + void vSizePolicy( SizePolicy ); + + void show(); + void hide(); + + void widgetDestroyed(); +}; + +class KWidgetGuard : public QObject { + Q_OBJECT +protected: + KWidget_impl *impl; + +public: + KWidgetGuard(KWidget_impl *impl) : impl(impl) { } + +public slots: + void widgetDestroyed() { + impl->widgetDestroyed(); + } +}; + +} +#endif /* ARTS_GUI_KWIDGET_IMPL_H */ + +// vim: sw=4 ts=4 diff --git a/arts/gui/kde/kwidgetrepo.cpp b/arts/gui/kde/kwidgetrepo.cpp new file mode 100644 index 00000000..43dd122d --- /dev/null +++ b/arts/gui/kde/kwidgetrepo.cpp @@ -0,0 +1,89 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#include "kwidgetrepo.h" +#include "kwidget_impl.h" +#include + +using namespace Arts; + +class KWidgetRepoShutdown : public StartupClass { +public: + void startup() {}; + void shutdown() + { + KWidgetRepo::shutdown(); + } +}; + +KWidgetRepo *KWidgetRepo::instance = 0; + +KWidgetRepo *KWidgetRepo::the() +{ + if(!instance) + instance = new KWidgetRepo(); + return instance; +} + +void KWidgetRepo::shutdown() +{ + if(instance) + { + delete instance; + instance = 0; + } +} + +KWidgetRepo::KWidgetRepo() + : nextID(1) +{ +} + +KWidgetRepo::~KWidgetRepo() +{ +} + + +long KWidgetRepo::add(KWidget_impl *widget, QWidget *qwidget) +{ + long ID = nextID++; + widgets[ID] = widget; + qwidgets[ID] = qwidget; + return ID; +} + +QWidget *KWidgetRepo::lookupQWidget(long ID) +{ + return qwidgets[ID]; +} + +Widget KWidgetRepo::lookupWidget(long ID) +{ + if(qwidgets[ID]) /* check existence */ + return Arts::Widget::_from_base(widgets[ID]->_copy()); + return Arts::Widget::null(); +} + +void KWidgetRepo::remove(long ID) +{ + widgets.erase(ID); +} diff --git a/arts/gui/kde/kwidgetrepo.h b/arts/gui/kde/kwidgetrepo.h new file mode 100644 index 00000000..e60cc011 --- /dev/null +++ b/arts/gui/kde/kwidgetrepo.h @@ -0,0 +1,56 @@ + /* + + Copyright (C) 2000 Stefan Westerfeld + stefan@space.twc.de + + 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. + + */ + +#ifndef KWIDGETREPO_H +#define KWIDGETREPO_H + +#include +#include +#include +#include "artsgui.h" + +namespace Arts { + class KWidget_impl; +} + +class KWidgetRepo { +protected: + long nextID; + std::map qwidgets; + std::map widgets; + static KWidgetRepo *instance; + + KWidgetRepo(); + ~KWidgetRepo(); + +public: + + long add(Arts::KWidget_impl *widget, QWidget *qwidget); + Arts::Widget lookupWidget(long ID); + QWidget *lookupQWidget(long ID); + void remove(long ID); + + static KWidgetRepo *the(); + static void shutdown(); +}; + +#endif /* KWIDGETREPO_H */ diff --git a/arts/gui/kde/mcopclass/Button.mcopclass b/arts/gui/kde/mcopclass/Button.mcopclass new file mode 100644 index 00000000..d5e06c30 --- /dev/null +++ b/arts/gui/kde/mcopclass/Button.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::Button,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/Fader.mcopclass b/arts/gui/kde/mcopclass/Fader.mcopclass new file mode 100644 index 00000000..4071180d --- /dev/null +++ b/arts/gui/kde/mcopclass/Fader.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::Fader,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/Graph.mcopclass b/arts/gui/kde/mcopclass/Graph.mcopclass new file mode 100644 index 00000000..f1d98d3a --- /dev/null +++ b/arts/gui/kde/mcopclass/Graph.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::Graph,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/GraphLine.mcopclass b/arts/gui/kde/mcopclass/GraphLine.mcopclass new file mode 100644 index 00000000..57b48f2c --- /dev/null +++ b/arts/gui/kde/mcopclass/GraphLine.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::GraphLine,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/HBox.mcopclass b/arts/gui/kde/mcopclass/HBox.mcopclass new file mode 100644 index 00000000..fce0f113 --- /dev/null +++ b/arts/gui/kde/mcopclass/HBox.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::HBox,Arts::Frame,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/Label.mcopclass b/arts/gui/kde/mcopclass/Label.mcopclass new file mode 100644 index 00000000..2bad3990 --- /dev/null +++ b/arts/gui/kde/mcopclass/Label.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::Label,Arts::Frame,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/LayoutBox.mcopclass b/arts/gui/kde/mcopclass/LayoutBox.mcopclass new file mode 100644 index 00000000..48292c85 --- /dev/null +++ b/arts/gui/kde/mcopclass/LayoutBox.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::LayoutBox,Arts::Frame,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/LevelMeter.mcopclass b/arts/gui/kde/mcopclass/LevelMeter.mcopclass new file mode 100644 index 00000000..77f804b9 --- /dev/null +++ b/arts/gui/kde/mcopclass/LevelMeter.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::LevelMeter,Arts::Frame,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/LineEdit.mcopclass b/arts/gui/kde/mcopclass/LineEdit.mcopclass new file mode 100644 index 00000000..69b68703 --- /dev/null +++ b/arts/gui/kde/mcopclass/LineEdit.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::LineEdit,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/Makefile.am b/arts/gui/kde/mcopclass/Makefile.am new file mode 100644 index 00000000..fac44b22 --- /dev/null +++ b/arts/gui/kde/mcopclass/Makefile.am @@ -0,0 +1,5 @@ +mcopclassdir = $(libdir)/mcop/Arts +mcopclass_DATA = Widget.mcopclass Button.mcopclass Poti.mcopclass \ + LineEdit.mcopclass HBox.mcopclass VBox.mcopclass SpinBox.mcopclass \ + Fader.mcopclass GraphLine.mcopclass LayoutBox.mcopclass \ + PopupBox.mcopclass LevelMeter.mcopclass Label.mcopclass diff --git a/arts/gui/kde/mcopclass/PopupBox.mcopclass b/arts/gui/kde/mcopclass/PopupBox.mcopclass new file mode 100644 index 00000000..5ac282d1 --- /dev/null +++ b/arts/gui/kde/mcopclass/PopupBox.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::PopupBox,Arts::Frame,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/Poti.mcopclass b/arts/gui/kde/mcopclass/Poti.mcopclass new file mode 100644 index 00000000..cae9a5e9 --- /dev/null +++ b/arts/gui/kde/mcopclass/Poti.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::Poti,Arts::Frame,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/SpinBox.mcopclass b/arts/gui/kde/mcopclass/SpinBox.mcopclass new file mode 100644 index 00000000..68cfc5eb --- /dev/null +++ b/arts/gui/kde/mcopclass/SpinBox.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::SpinBox,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/VBox.mcopclass b/arts/gui/kde/mcopclass/VBox.mcopclass new file mode 100644 index 00000000..b32c302e --- /dev/null +++ b/arts/gui/kde/mcopclass/VBox.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::VBox,Arts::Frame,Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui diff --git a/arts/gui/kde/mcopclass/Widget.mcopclass b/arts/gui/kde/mcopclass/Widget.mcopclass new file mode 100644 index 00000000..54a6e91f --- /dev/null +++ b/arts/gui/kde/mcopclass/Widget.mcopclass @@ -0,0 +1,5 @@ +Buildable=true +Interface=Arts::Widget,Arts::Object +Language=C++ +Library=libartsgui_kde.la +Requires=kdegui -- cgit v1.2.3