summaryrefslogtreecommitdiff
authorchicken <chicken>2004-03-01 17:53:46 (UTC)
committer chicken <chicken>2004-03-01 17:53:46 (UTC)
commit5b4e342004537f84fa53911a46cd00d810378da7 (patch) (side-by-side diff)
tree763c74ad41014de91c010fb996ec527f841ef3bc
parent5b640d3f070b0b2de361421abf93949410546e19 (diff)
downloadopie-5b4e342004537f84fa53911a46cd00d810378da7.zip
opie-5b4e342004537f84fa53911a46cd00d810378da7.tar.gz
opie-5b4e342004537f84fa53911a46cd00d810378da7.tar.bz2
fix includes
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/citytime/citytime.cpp5
-rw-r--r--core/settings/citytime/citytimebase.cpp3
-rw-r--r--core/settings/citytime/main.cpp1
-rw-r--r--core/settings/citytime/stylusnormalizer.cpp1
-rw-r--r--core/settings/citytime/zonemap.cpp7
-rw-r--r--core/settings/light-and-power/light.cpp1
-rw-r--r--libqtaux/ocolorbutton.cpp3
-rw-r--r--libqtaux/ocolorpopupmenu.cpp1
-rw-r--r--libqtaux/qcolordialog.cpp2
-rw-r--r--libqtaux/qinputdialog.cpp1
-rw-r--r--libqtaux/qsplitter.cpp4
11 files changed, 0 insertions, 29 deletions
diff --git a/core/settings/citytime/citytime.cpp b/core/settings/citytime/citytime.cpp
index b359ae1..e7f0c46 100644
--- a/core/settings/citytime/citytime.cpp
+++ b/core/settings/citytime/citytime.cpp
@@ -1,284 +1,279 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
// changes by Maximilian Reiss <harlekin@handhelds.org>
#include "zonemap.h"
#include "citytime.h"
#include <qpe/qpeapplication.h>
#include <qpe/config.h>
-#include <qpe/timestring.h>
#include <qpe/tzselect.h>
#if !defined(QT_NO_COP)
#include <qpe/qcopenvelope_qws.h>
#endif
-#include <qdir.h>
-#include <qfile.h>
#include <qlabel.h>
#include <qmessagebox.h>
-#include <qregexp.h>
-#include <qtextstream.h>
#include <qtoolbutton.h>
#include <qlayout.h>
#include <stdlib.h>
CityTime::CityTime( QWidget *parent, const char* name,
WFlags fl )
: CityTimeBase( parent, name, fl ),
strRealTz(0),
bAdded(false)
{
Config config( "qpe" );
config.setGroup( "Time" );
bWhichClock = config.readBoolEntry( "AMPM", TRUE );
qDebug( QString("%1").arg(bWhichClock) );
frmMap->changeClock( bWhichClock );
char *pEnv;
pEnv = NULL;
pEnv = getenv("TZ");
if ( pEnv )
strRealTz = pEnv;
pEnv = NULL;
pEnv = getenv("HOME");
if ( pEnv )
strHome = pEnv;
// append the labels to their respective lists...
listCities.setAutoDelete( true );
listTimes.setAutoDelete( true );
listCities.append( cmdCity1 );
listCities.append( cmdCity2 );
listCities.append( cmdCity3 );
listTimes.append( lblCTime1 );
listTimes.append( lblCTime2 );
listTimes.append( lblCTime3 );
// kludgy way of getting the screen size so we don't have to depend
// on a resize event...
QWidget *d = QApplication::desktop();
if ( d->width() < d->height() ) {
// append for that 4 down look
listCities.append( cmdCity4 );
listCities.append( cmdCity5 );
listCities.append( cmdCity6 );
listTimes.append( lblCTime4 );
listTimes.append( lblCTime5 );
listTimes.append( lblCTime6 );
lblCTime7->hide();
lblCTime8->hide();
lblCTime9->hide();
cmdCity7->hide();
cmdCity8->hide();
cmdCity9->hide();
} else {
listCities.append( cmdCity7 );
listCities.append( cmdCity8 );
listCities.append( cmdCity9 );
listTimes.append( lblCTime7 );
listTimes.append( lblCTime8 );
listTimes.append( lblCTime9 );
lblCTime4->hide();
lblCTime5->hide();
lblCTime6->hide();
cmdCity4->hide();
cmdCity5->hide();
cmdCity6->hide();
}
selWidget = frmMap->selectionWidget( this );
selWidget->hide();
CityTimeBaseLayout->addWidget( selWidget );
bAdded = true;
readInTimes();
changed = FALSE;
QObject::connect( qApp, SIGNAL( clockChanged( bool ) ),
this, SLOT( changeClock( bool ) ) );
// now start the timer so we can update the time quickly every second
timerEvent( 0 );
}
CityTime::~CityTime()
{
if ( changed ) {
Config cfg("CityTime");
cfg.setGroup("TimeZones");
QListIterator<QToolButton> itCity( listCities );
int i;
bool realTzWritten = FALSE;
for ( i = 0, itCity.toFirst(); i < CITIES; i++, ++itCity ) {
if ( !strCityTz[i].isNull() ) {
cfg.writeEntry("Zone"+QString::number(i), strCityTz[i]);
cfg.writeEntry("ZoneName"+QString::number(i), itCity.current()->text());
if ( strCityTz[i] == strRealTz )
realTzWritten = TRUE;
}
}
if ( realTzWritten ) {
cfg.removeEntry("Zone"+QString::number(CITIES));
cfg.removeEntry("ZoneName"+QString::number(CITIES));
} else {
cfg.writeEntry("Zone"+QString::number(CITIES), strRealTz);
if ( nameRealTz.isEmpty() ) {
int i = strRealTz.find( '/' );
nameRealTz = strRealTz.mid( i+1 );
}
cfg.writeEntry("ZoneName"+QString::number(CITIES), nameRealTz);
}
QCopEnvelope ( "QPE/System", "timeZoneListChange()" );
changed = FALSE;
}
// restore the timezone, just in case we messed with it and
// are destroyed at an inoppurtune moment
if ( !strRealTz.isNull() ) {
// this should be checked, but there is not much that can done at this
//point if it fails
setenv( "TZ", strRealTz, true );
}
}
void CityTime::timerEvent( QTimerEvent *e )
{
if ( e )
killTimer( timerId );
// change the time again!!
showTime();
int ms = 1000 - QTime::currentTime().msec();
timerId = startTimer( ms );
}
void CityTime::mousePressEvent( QMouseEvent * )
{
// DEBUG enable this to get a look at the zone information DEBUG
// frmMap->showZones();
}
void CityTime::showTime( void )
{
int i;
QListIterator<QLabel> itTime(listTimes);
// traverse the list...
for ( i = 0, itTime.toFirst(); i < CITIES; i++, ++itTime) {
if ( !strCityTz[i].isNull() ) {
if ( setenv( "TZ", strCityTz[i], true ) == 0 ) {
itTime.current()->setText( TimeString::shortTime( bWhichClock ) );
} else {
QMessageBox::critical( this, tr( "Time Changing" ),
tr( "There was a problem setting timezone %1" )
.arg( QString::number( i + 1 ) ) );
}
}
}
// done playing around... put it all back
unsetenv( "TZ" );
if ( !strRealTz.isNull() ) {
if ( setenv( "TZ", strRealTz, true ) != 0 ) {
QMessageBox::critical( this, tr( "Restore Time Zone" ),
tr( "There was a problem setting your timezone."
"Your time may be wrong now..." ) );
}
}
}
void CityTime::beginNewTz()
{
buttonWidget->hide();
frmMap->setFocus();
selWidget->show();
// CityTimeBaseLayout->addWidget( selWidget );
}
void CityTime::slotNewTz( const QString & strNewCountry,
const QString & strNewCity )
{
// determine what to do based on what putton is pressed...
QListIterator<QToolButton> itCity(listCities);
int i;
// go through the list and make adjustments based on which button is on
for ( i = 0, itCity.toFirst(); itCity.current(), i < CITIES; i++, ++itCity ) {
QToolButton *cmdTmp = itCity.current();
if ( cmdTmp->isOn() ) {
strCityTz[i] = strNewCountry + strNewCity;
QString s = strNewCity;
cmdTmp->setText( s.replace( QRegExp("_"), " " ) );
cmdTmp->toggle();
// we can actually break, since there is only one button
// that is ever pressed!
changed = TRUE;
break;
}
}
showTime();
buttonWidget->show();
selWidget->hide();
}
void CityTime::readInTimes( void )
{
Config cfg("CityTime");
cfg.setGroup("TimeZones");
QListIterator<QToolButton> itCity( listCities );
int i=0;
nameRealTz = QString::null;
QString zn;
for ( ; i < CITIES ; i++ ) {
zn = cfg.readEntry("Zone"+QString::number(i), QString::null);
if ( zn.isNull() )
break;
QString nm = cfg.readEntry("ZoneName"+QString::number(i));
strCityTz[i] = zn;
itCity.current()->setText(nm);
if ( zn == strRealTz )
nameRealTz = nm;
++itCity;
}
if ( i == 0 ) {
// write in our own in a shameless self promotion and some humor
QStringList list = timezoneDefaults();
int i;
QStringList::Iterator it = list.begin();
for ( i = 0, itCity.toFirst(); i < CITIES && itCity.current();
i++, ++itCity ) {
strCityTz[i] = *it++;
itCity.current()->setText( *it++ );
}
}
if ( nameRealTz.isEmpty() ) {
//remember the current time zone even if we don't have room
//to show it.
zn = cfg.readEntry("Zone"+QString::number(CITIES), QString::null);
if ( zn == strRealTz )
nameRealTz = cfg.readEntry("ZoneName"+QString::number(CITIES));
i++;
}
}
void CityTime::changeClock( bool newClock )
{
bWhichClock = newClock;
showTime();
}
diff --git a/core/settings/citytime/citytimebase.cpp b/core/settings/citytime/citytimebase.cpp
index d734cf3..a3483cc 100644
--- a/core/settings/citytime/citytimebase.cpp
+++ b/core/settings/citytime/citytimebase.cpp
@@ -1,414 +1,411 @@
// changes by Maximilian Reiss <harlekin@handhelds.org>
#include "citytimebase.h"
#include <qlabel.h>
-#include <qpushbutton.h>
#include <qtoolbutton.h>
#include "zonemap.h"
#include <qlayout.h>
-#include <qvariant.h>
-#include <qtooltip.h>
#include <qwhatsthis.h>
/*
* Constructs a CityTimeBase which is a child of 'parent', with the
* name 'name' and widget flags set to 'f'
*/
CityTimeBase::CityTimeBase( QWidget* parent, const char* name, WFlags )
: QWidget( parent, name, WStyle_ContextHelp )
{
if ( !name )
setName( "CityTimeBase" );
setCaption( tr( "City Time" ) );
CityTimeBaseLayout = new QVBoxLayout( this );
CityTimeBaseLayout->setSpacing( 3 );
CityTimeBaseLayout->setMargin( 0 );
frmMap = new ZoneMap( this, "frmMap" );
frmMap->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)7, (QSizePolicy::SizeType)7, frmMap->sizePolicy().hasHeightForWidth() ) );
CityTimeBaseLayout->addWidget( frmMap );
buttonWidget = new QWidget( this );
QWhatsThis::add( buttonWidget, tr( "Click on one of the set cities to replace it" ) );
Layout2 = new QGridLayout( buttonWidget );
Layout2->setSpacing( 3 );
Layout2->setMargin( 4 );
cmdCity7 = new QToolButton( buttonWidget, "cmdCity7" );
cmdCity7->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity7->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity7_font( cmdCity7->font() );
cmdCity7_font.setBold( TRUE );
cmdCity7->setFont( cmdCity7_font );
cmdCity7->setFocusPolicy( QToolButton::TabFocus );
cmdCity7->setText( tr( "" ) );
cmdCity7->setToggleButton( TRUE );
cmdCity7->setToggleButton( TRUE );
Layout2->addWidget( cmdCity7, 0, 2 );
lblCTime9 = new QLabel( buttonWidget, "lblCTime9" );
lblCTime9->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, lblCTime9->sizePolicy().hasHeightForWidth() ) );
QFont lblCTime9_font( lblCTime9->font() );
lblCTime9_font.setPointSize( 10 );
lblCTime9->setFont( lblCTime9_font );
lblCTime9->setText( tr( "" ) );
lblCTime9->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime9, 2, 3 );
cmdCity8 = new QToolButton( buttonWidget, "cmdCity8" );
cmdCity8->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity8->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity8_font( cmdCity8->font() );
cmdCity8_font.setBold( TRUE );
cmdCity8->setFont( cmdCity8_font );
cmdCity8->setFocusPolicy( QToolButton::TabFocus );
cmdCity8->setText( tr( "" ) );
cmdCity8->setToggleButton( TRUE );
cmdCity8->setToggleButton( TRUE );
Layout2->addWidget( cmdCity8, 1, 2 );
cmdCity2 = new QToolButton( buttonWidget, "cmdCity2" );
QFont cmdCity2_font( cmdCity2->font() );
cmdCity2_font.setBold( TRUE );
cmdCity2->setFont( cmdCity2_font );
cmdCity2->setFocusPolicy( QToolButton::TabFocus );
cmdCity2->setText( tr( "" ) );
cmdCity2->setToggleButton( TRUE );
cmdCity2->setToggleButton( TRUE );
Layout2->addWidget( cmdCity2, 1, 0 );
lblCTime6 = new QLabel( buttonWidget, "lblCTime6" );
QFont lblCTime6_font( lblCTime6->font() );
lblCTime6_font.setPointSize( 10 );
lblCTime6->setFont( lblCTime6_font );
lblCTime6->setText( tr( "" ) );
lblCTime6->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime6, 5, 1 );
cmdCity6 = new QToolButton( buttonWidget, "cmdCity6" );
cmdCity6->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity6->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity6_font( cmdCity6->font() );
cmdCity6_font.setBold( TRUE );
cmdCity6->setFont( cmdCity6_font );
cmdCity6->setFocusPolicy( QToolButton::TabFocus );
cmdCity6->setText( tr( "" ) );
cmdCity6->setToggleButton( TRUE );
cmdCity6->setToggleButton( TRUE );
Layout2->addWidget( cmdCity6, 5, 0 );
cmdCity4 = new QToolButton( buttonWidget, "cmdCity4" );
cmdCity4->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity4->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity4_font( cmdCity4->font() );
cmdCity4_font.setBold( TRUE );
cmdCity4->setFont( cmdCity4_font );
cmdCity4->setFocusPolicy( QToolButton::TabFocus );
cmdCity4->setText( tr( "" ) );
cmdCity4->setToggleButton( TRUE );
cmdCity4->setToggleButton( TRUE );
Layout2->addWidget( cmdCity4, 3, 0 );
lblCTime5 = new QLabel( buttonWidget, "lblCTime5" );
QFont lblCTime5_font( lblCTime5->font() );
lblCTime5_font.setPointSize( 10 );
lblCTime5->setFont( lblCTime5_font );
lblCTime5->setText( tr( "" ) );
lblCTime5->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime5, 4, 1 );
lblCTime2 = new QLabel( buttonWidget, "lblCTime2" );
lblCTime2->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, lblCTime2->sizePolicy().hasHeightForWidth() ) );
QFont lblCTime2_font( lblCTime2->font() );
lblCTime2_font.setPointSize( 10 );
lblCTime2->setFont( lblCTime2_font );
lblCTime2->setText( tr( "" ) );
lblCTime2->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime2, 1, 1 );
lblCTime1 = new QLabel( buttonWidget, "lblCTime1" );
lblCTime1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)1, (QSizePolicy::SizeType)1, lblCTime1->sizePolicy().hasHeightForWidth() ) );
QFont lblCTime1_font( lblCTime1->font() );
lblCTime1_font.setPointSize( 10 );
lblCTime1->setFont( lblCTime1_font );
lblCTime1->setText( tr( "" ) );
lblCTime1->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime1, 0, 1 );
cmdCity3 = new QToolButton( buttonWidget, "cmdCity3" );
cmdCity3->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity3->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity3_font( cmdCity3->font() );
cmdCity3_font.setBold( TRUE );
cmdCity3->setFont( cmdCity3_font );
cmdCity3->setFocusPolicy( QToolButton::TabFocus );
cmdCity3->setText( tr( "" ) );
cmdCity3->setToggleButton( TRUE );
cmdCity3->setToggleButton( TRUE );
Layout2->addWidget( cmdCity3, 2, 0 );
lblCTime8 = new QLabel( buttonWidget, "lblCTime8" );
lblCTime8->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, lblCTime8->sizePolicy().hasHeightForWidth() ) );
QFont lblCTime8_font( lblCTime8->font() );
lblCTime8_font.setPointSize( 10 );
lblCTime8->setFont( lblCTime8_font );
lblCTime8->setText( tr( "" ) );
lblCTime8->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime8, 1, 3 );
cmdCity1 = new QToolButton( buttonWidget, "cmdCity1" );
cmdCity1->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity1->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity1_font( cmdCity1->font() );
cmdCity1_font.setBold( TRUE );
cmdCity1->setFont( cmdCity1_font );
cmdCity1->setFocusPolicy( QToolButton::TabFocus );
cmdCity1->setText( tr( "" ) );
cmdCity1->setToggleButton( TRUE );
cmdCity1->setToggleButton( TRUE );
Layout2->addWidget( cmdCity1, 0, 0 );
lblCTime7 = new QLabel( buttonWidget, "lblCTime7" );
lblCTime7->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, lblCTime7->sizePolicy().hasHeightForWidth() ) );
QFont lblCTime7_font( lblCTime7->font() );
lblCTime7_font.setPointSize( 10 );
lblCTime7->setFont( lblCTime7_font );
lblCTime7->setText( tr( "" ) );
lblCTime7->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime7, 0, 3 );
lblCTime4 = new QLabel( buttonWidget, "lblCTime4" );
QFont lblCTime4_font( lblCTime4->font() );
lblCTime4_font.setPointSize( 10 );
lblCTime4->setFont( lblCTime4_font );
lblCTime4->setText( tr( "" ) );
lblCTime4->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime4, 3, 1 );
cmdCity5 = new QToolButton( buttonWidget, "cmdCity5" );
cmdCity5->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity5->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity5_font( cmdCity5->font() );
cmdCity5_font.setBold( TRUE );
cmdCity5->setFont( cmdCity5_font );
cmdCity5->setFocusPolicy( QToolButton::TabFocus );
cmdCity5->setText( tr( "" ) );
cmdCity5->setToggleButton( TRUE );
cmdCity5->setToggleButton( TRUE );
Layout2->addWidget( cmdCity5, 4, 0 );
lblCTime3 = new QLabel( buttonWidget, "lblCTime3" );
QFont lblCTime3_font( lblCTime3->font() );
lblCTime3_font.setPointSize( 10 );
lblCTime3->setFont( lblCTime3_font );
lblCTime3->setText( tr( "" ) );
lblCTime3->setAlignment( int( QLabel::AlignVCenter | QLabel::AlignRight ) );
Layout2->addWidget( lblCTime3, 2, 1 );
cmdCity9 = new QToolButton( buttonWidget, "cmdCity9" );
cmdCity9->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)5, (QSizePolicy::SizeType)1, cmdCity9->sizePolicy().hasHeightForWidth() ) );
QFont cmdCity9_font( cmdCity9->font() );
cmdCity9_font.setBold( TRUE );
cmdCity9->setFont( cmdCity9_font );
cmdCity9->setFocusPolicy( QToolButton::TabFocus );
cmdCity9->setText( tr( "" ) );
cmdCity9->setToggleButton( TRUE );
cmdCity9->setToggleButton( TRUE );
Layout2->addWidget( cmdCity9, 2, 2 );
CityTimeBaseLayout->addWidget( buttonWidget );
// signals and slots connections
connect( frmMap, SIGNAL( signalTz(const QString &, const QString &) ), this, SLOT( slotNewTz(const QString &, const QString &) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity1, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity3, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity4, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity5, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity6, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity7, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity8, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), cmdCity9, SLOT( setDisabled(bool) ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), cmdCity2, SLOT( setDisabled(bool) ) );
connect( cmdCity1, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity2, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity7, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity3, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity4, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity5, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity6, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity8, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
connect( cmdCity9, SIGNAL( toggled(bool) ), this, SLOT( beginNewTz() ) );
// tab order
setTabOrder( cmdCity1, cmdCity2 );
setTabOrder( cmdCity2, cmdCity3 );
setTabOrder( cmdCity3, cmdCity4 );
setTabOrder( cmdCity4, cmdCity5 );
setTabOrder( cmdCity5, cmdCity6 );
setTabOrder( cmdCity6, cmdCity7 );
setTabOrder( cmdCity7, cmdCity8 );
setTabOrder( cmdCity8, cmdCity9 );
setTabOrder( cmdCity9, frmMap );
}
/*
* Destroys the object and frees any allocated resources
*/
CityTimeBase::~CityTimeBase()
{
// no need to delete child widgets, Qt does it all for us
}
/*
* Main event handler. Reimplemented to handle application
* font changes
*/
bool CityTimeBase::event( QEvent* ev )
{
bool ret = QWidget::event( ev );
if ( ev->type() == QEvent::ApplicationFontChange ) {
QFont cmdCity7_font( cmdCity7->font() );
cmdCity7_font.setBold( TRUE );
cmdCity7->setFont( cmdCity7_font );
QFont lblCTime9_font( lblCTime9->font() );
lblCTime9_font.setPointSize( 10 );
lblCTime9->setFont( lblCTime9_font );
QFont cmdCity8_font( cmdCity8->font() );
cmdCity8_font.setBold( TRUE );
cmdCity8->setFont( cmdCity8_font );
QFont cmdCity2_font( cmdCity2->font() );
cmdCity2_font.setBold( TRUE );
cmdCity2->setFont( cmdCity2_font );
QFont lblCTime6_font( lblCTime6->font() );
lblCTime6_font.setPointSize( 10 );
lblCTime6->setFont( lblCTime6_font );
QFont cmdCity6_font( cmdCity6->font() );
cmdCity6_font.setBold( TRUE );
cmdCity6->setFont( cmdCity6_font );
QFont cmdCity4_font( cmdCity4->font() );
cmdCity4_font.setBold( TRUE );
cmdCity4->setFont( cmdCity4_font );
QFont lblCTime5_font( lblCTime5->font() );
lblCTime5_font.setPointSize( 10 );
lblCTime5->setFont( lblCTime5_font );
QFont lblCTime2_font( lblCTime2->font() );
lblCTime2_font.setPointSize( 10 );
lblCTime2->setFont( lblCTime2_font );
QFont lblCTime1_font( lblCTime1->font() );
lblCTime1_font.setPointSize( 10 );
lblCTime1->setFont( lblCTime1_font );
QFont cmdCity3_font( cmdCity3->font() );
cmdCity3_font.setBold( TRUE );
cmdCity3->setFont( cmdCity3_font );
QFont lblCTime8_font( lblCTime8->font() );
lblCTime8_font.setPointSize( 10 );
lblCTime8->setFont( lblCTime8_font );
QFont cmdCity1_font( cmdCity1->font() );
cmdCity1_font.setBold( TRUE );
cmdCity1->setFont( cmdCity1_font );
QFont lblCTime7_font( lblCTime7->font() );
lblCTime7_font.setPointSize( 10 );
lblCTime7->setFont( lblCTime7_font );
QFont lblCTime4_font( lblCTime4->font() );
lblCTime4_font.setPointSize( 10 );
lblCTime4->setFont( lblCTime4_font );
QFont cmdCity5_font( cmdCity5->font() );
cmdCity5_font.setBold( TRUE );
cmdCity5->setFont( cmdCity5_font );
QFont lblCTime3_font( lblCTime3->font() );
lblCTime3_font.setPointSize( 10 );
lblCTime3->setFont( lblCTime3_font );
QFont cmdCity9_font( cmdCity9->font() );
cmdCity9_font.setBold( TRUE );
cmdCity9->setFont( cmdCity9_font );
}
return ret;
}
void CityTimeBase::beginNewTz()
{
qWarning( "CityTimeBase::beginNewTz(): Not implemented yet!" );
}
void CityTimeBase::slotNewTz(const QString &, const QString &)
{
qWarning( "CityTimeBase::slotNewTz(const QString &, const QString &): Not implemented yet!" );
}
diff --git a/core/settings/citytime/main.cpp b/core/settings/citytime/main.cpp
index 69bfe44..59498b7 100644
--- a/core/settings/citytime/main.cpp
+++ b/core/settings/citytime/main.cpp
@@ -1,25 +1,24 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "citytime.h"
-#include <qpe/qpeapplication.h>
#include <opie/oapplicationfactory.h>
OPIE_EXPORT_APP( OApplicationFactory<CityTime> )
diff --git a/core/settings/citytime/stylusnormalizer.cpp b/core/settings/citytime/stylusnormalizer.cpp
index c6c65d2..281a0bc 100644
--- a/core/settings/citytime/stylusnormalizer.cpp
+++ b/core/settings/citytime/stylusnormalizer.cpp
@@ -1,99 +1,98 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
-#include <qpoint.h>
#include <qtimer.h>
#include "stylusnormalizer.h"
static const int FLUSHTIME = 100;
_StylusEvent::_StylusEvent( const QPoint& newPt )
: _pt( newPt ),
_t( QTime::currentTime() )
{
}
_StylusEvent::~_StylusEvent()
{
}
StylusNormalizer::StylusNormalizer( QWidget *parent, const char* name )
: QWidget( parent, name ),
_next( 0 ),
bFirst( true )
{
// initialize _ptList
int i;
for (i = 0; i < SAMPLES; i++ ) {
_ptList[i].setPoint( -1, -1 );
}
_tExpire = new QTimer( this );
QObject::connect( _tExpire, SIGNAL( timeout() ),
this, SLOT( slotAveragePoint() ) );
}
StylusNormalizer::~StylusNormalizer()
{
}
void StylusNormalizer::addEvent( const QPoint& pt )
{
_ptList[_next].setPoint( pt );
_ptList[_next++].setTime( QTime::currentTime() );
if ( _next >= SAMPLES ) {
_next = 0;
}
// make a single mouse click work
if ( bFirst ) {
slotAveragePoint();
bFirst = false;
}
}
void StylusNormalizer::slotAveragePoint( void )
{
QPoint pt( 0, 0 );
QTime tCurr = QTime::currentTime();
int i,
size;
size = 0;
for ( i = 0; i < SAMPLES; i++ ) {
if ( ( (_ptList[i]).time().msecsTo( tCurr ) < FLUSHTIME ) &&
( _ptList[i].point() != QPoint( -1, -1 ) ) ) {
pt += _ptList[i].point();
size++;
}
}
if ( size > 0 )
emit signalNewPoint( pt /= size );
}
void StylusNormalizer::start( void )
{
_tExpire->start( FLUSHTIME );
}
void StylusNormalizer::stop( void )
{
_tExpire->stop();
bFirst = true;
}
diff --git a/core/settings/citytime/zonemap.cpp b/core/settings/citytime/zonemap.cpp
index 872e786..b83da59 100644
--- a/core/settings/citytime/zonemap.cpp
+++ b/core/settings/citytime/zonemap.cpp
@@ -1,731 +1,724 @@
/**********************************************************************
** Copyright (C) 2000 Trolltech AS. All rights reserved.
**
** This file is part of Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
// changes by Maximilian Reiss <harlekin@handhelds.org>
#include "sun.h"
#include "zonemap.h"
#include <qpe/resource.h>
-#include <qpe/timestring.h>
#include <qpe/qpeapplication.h>
-#include <qdatetime.h>
#include <qfile.h>
-#include <qimage.h>
#include <qlabel.h>
-#include <qlist.h>
#include <qmessagebox.h>
-#include <qpixmap.h>
-#include <qpainter.h>
-#include <qregexp.h>
#include <qtextstream.h>
#include <qtimer.h>
#include <qtoolbutton.h>
#include <qlayout.h>
#include <qhbox.h>
#include <qlistview.h>
#include <qwhatsthis.h>
#include <limits.h>
// the map file...
static const char strZONEINFO[] = "/usr/share/zoneinfo/zone.tab";
static const char strMAP[] = "citytime/simple_grid_400";
// the maximum distance we'll allow the pointer to be away from a city
// and still show the city's time
static const int iTHRESHOLD = 50000;
// The label offset (how far away from pointer)
static const int iLABELOFFSET = 8;
// the size of the dot to draw, and where to start it
static const int iCITYSIZE = 3;
const int iCITYOFFSET = 2;
// the darkening function
static inline void darken( QImage *pImage, int start, int stop, int row );
static void dayNight( QImage *pImage );
ZoneField::ZoneField( const QString& strLine )
{
// make a bunch of RegExp's to match the data from the line
QRegExp regCoord( "[-+][0-9]+" ); // the latitude
QRegExp regCountry( "[A-Za-z]+/" ); // the country (not good enough)
QRegExp regCity( "[A-Za-z_-]*" ); // the city
int iStart,
iStop,
iLen,
tmp;
QString strTmp;
// we should be able to assume that the country code is always the first
// two chars, so just grap them and let it go...
strCountryCode = strLine.left( 2 );
iStart = regCoord.match( strLine, 0, &iLen );
if ( iStart >= 0 ) {
strTmp = strLine.mid( iStart, iLen );
tmp = strTmp.toInt();
// okay, there are two versions of the format, make a decision based on
// the size...
// Oh BTW, we are storing everything in seconds!
if ( iLen < 7 ) {
_y = tmp / 100;
_y *= 60;
_y += tmp % 100;
_y *= 60;
} else {
_y = tmp / 10000;
_y *= 60;
tmp %= 10000;
_y += tmp / 100;
_y *= 60;
tmp %= 100;
_y += tmp;
}
}
iStart = regCoord.match( strLine, iStart + iLen, &iLen );
if ( iStart >= 0 ) {
strTmp = strLine.mid( iStart, iLen );
tmp = strTmp.toInt();
if ( iLen < 8 ) {
_x = tmp / 100;
_x *= 60;
_x += tmp % 100;
_x *= 60;
} else {
_x = tmp / 10000;
_x *= 60;
tmp %= 10000;
_x += tmp / 100;
_x *= 60;
tmp %= 100;
_x += tmp;
}
}
iStart = regCountry.match( strLine, 0, &iLen );
// help with the shortcoming in 2.x regexp...
iStop = strLine.findRev( '/' );
if ( iStart >= 0 ) {
iLen = (iStop - iStart) + 1;
strCountry = strLine.mid( iStart, iLen );
}
// now match the city...
iStart = regCity.match( strLine, iStart + iLen, &iLen );
if ( iStart >= 0 ) {
strCity = strLine.mid( iStart, iLen );
}
}
void ZoneField::showStructure( void ) const
{
qDebug( "Country: %s", strCountry.latin1() );
qDebug( "City: %s", strCity.latin1() );
qDebug( "x: %d", _x );
qDebug( "y: %d\n", _y );
}
ZoneMap::ZoneMap( QWidget *parent, const char* name )
: QScrollView( parent, name ),
pLast( 0 ),
pRepaint( 0 ),
ox( 0 ),
oy( 0 ),
drawableW( -1 ),
drawableH( -1 ),
bZoom( FALSE ),
bIllum( TRUE ),
cursor( 0 )
{
viewport()->setFocusPolicy( StrongFocus );
// set mouse tracking so we can use the mouse move event
zones.setAutoDelete( true );
// get the map loaded
// just set the current image to point
pixCurr = new QPixmap();
QPixmap pixZoom = Resource::loadPixmap( "mag" );
cmdZoom = new QToolButton( this, "Zoom command" );
cmdZoom->setPixmap( pixZoom );
cmdZoom->setToggleButton( true );
cmdZoom->setSizePolicy( QSizePolicy( (QSizePolicy::SizeType)0,
(QSizePolicy::SizeType)0,
cmdZoom->sizePolicy().hasHeightForWidth() ) );
cmdZoom->setMaximumSize( cmdZoom->sizeHint() );
// probably don't need this, but just in case...
cmdZoom->move( width() - cmdZoom->width(), height() - cmdZoom->height() );
lblCity = new QLabel( tr( "CITY" ), this, "City Label" );
lblCity->setMinimumSize( lblCity->sizeHint() );
lblCity->setFrameStyle( QFrame::Plain | QFrame::Box );
lblCity->setBackgroundColor( yellow );
lblCity->hide();
// A timer to make sure the label gets hidden
tHide = new QTimer( this, "Label Timer" );
QObject::connect( tHide, SIGNAL( timeout() ),
lblCity, SLOT( hide() ) );
QObject::connect( tHide, SIGNAL( timeout() ),
this, SLOT( slotRedraw() ) );
QTimer *tUpdate = new QTimer( this, "Update Timer" );
QObject::connect( tUpdate, SIGNAL( timeout() ),
this, SLOT( slotUpdate() ) );
QObject::connect( qApp, SIGNAL( timeChanged() ),
this, SLOT( slotUpdate() ) );
QObject::connect( cmdZoom, SIGNAL( toggled( bool ) ),
this, SLOT( slotZoom( bool ) ) );
QObject::connect( &norm, SIGNAL( signalNewPoint( const QPoint& ) ),
this, SLOT( slotFindCity( const QPoint& ) ) );
QObject::connect( qApp, SIGNAL( clockChanged( bool ) ),
this, SLOT( changeClock( bool ) ) );
// update the sun's movement every 5 minutes
tUpdate->start( 5 * 60 * 1000 );
// May as well read in the timezone information too...
readZones();
}
ZoneMap::~ZoneMap()
{
}
void ZoneMap::readZones( void )
{
QFile fZone( strZONEINFO );
if ( !fZone.open( IO_ReadOnly ) ) {
QMessageBox::warning (this,
tr( "Unable to Find Timezone Info" ),
tr( "<p>Unable to find any timezone information in %1" )
.arg( strZONEINFO ));
exit(-1);
} else {
QTextStream tZone( &fZone );
while ( !tZone.atEnd() ) {
QString strLine = tZone.readLine();
// only pass on lines that aren't comments
if ( strLine[0] != '#' ) {
zones.append( new ZoneField( strLine ) );
}
}
fZone.close();
}
}
void ZoneMap::viewportMousePressEvent( QMouseEvent* event )
{
// add the mouse event into the normalizer, and get the average,
// pass it along
slotRedraw();
norm.start();
norm.addEvent( event->pos() );
}
void ZoneMap::viewportMouseMoveEvent( QMouseEvent* event )
{
norm.addEvent( event->pos() );
}
void ZoneMap::viewportMouseReleaseEvent( QMouseEvent* )
{
// get the averaged points in case a timeout hasn't occurred,
// more for "mouse clicks"
norm.stop();
if ( pLast != NULL ) {
emit signalTz( pLast->country(), pLast->city() );
pLast = NULL;
}
tHide->start( 2000, true );
}
void ZoneMap::keyPressEvent( QKeyEvent *ke )
{
switch ( ke->key() ) {
case Key_Left:
case Key_Right:
case Key_Up:
case Key_Down: {
tHide->stop();
if ( !cursor )
slotFindCity( QPoint( contentsWidth(), contentsHeight() ) / 2 );
ZoneField *city = findCityNear( cursor, ke->key() );
if ( city ) {
cursor = city;
int tmpx, tmpy;
zoneToWin( cursor->x(), cursor->y(), tmpx, tmpy );
ensureVisible( tmpx, tmpy );
showCity( cursor );
tHide->start( 3000, true );
}
}
break;
case Key_Space:
case Key_Enter:
case Key_Return:
if ( cursor ) {
emit signalTz( cursor->country(), cursor->city() );
tHide->start( 0, true );
}
break;
}
}
ZoneField *ZoneMap::findCityNear( ZoneField *city, int key )
{
ZoneField *pZone;
ZoneField *pClosest = 0;
long ddist = LONG_MAX;
QListIterator<ZoneField> it( zones );
for (; it.current(); ++it) {
pZone = it.current();
long dx = (pZone->x() - city->x())/100;
long dy = (pZone->y() - city->y())/100;
switch ( key ) {
case Key_Right:
case Key_Left:
if ( key == Key_Left )
dx = -dx;
if ( dx > 0 ) {
long dist = QABS(dy)*4 + dx;
if ( dist < ddist ) {
ddist = dist;
pClosest = pZone;
}
}
break;
case Key_Down:
case Key_Up:
if ( key == Key_Down )
dy = -dy;
if ( dy > 0 ) {
long dist = QABS(dx)*4 + dy;
if ( dist < ddist ) {
ddist = dist;
pClosest = pZone;
}
}
break;
}
}
return pClosest;
}
void ZoneMap::slotFindCity( const QPoint &pos )
{
lblCity->hide();
// given coordinates on the screen find the closest city and display the
// label close to it
int tmpx, tmpy, x, y;
long lDistance,
lClosest;
ZoneField *pZone,
*pClosest;
if ( tHide->isActive() ) {
tHide->stop();
}
viewportToContents(pos.x(), pos.y(), tmpx, tmpy);
winToZone( tmpx, tmpy, x, y );
// Find city alogorithim: start out at an (near) infinite distance away and
// then find the closest city, (similar to the Z-buffer technique, I guess)
// the only problem is that this is all done with doubles, but I don't know
// another way to do it at the moment. Another problem is a linked list is
// used obviously something indexed would help
QListIterator<ZoneField> it( zones );
pClosest = 0;
lClosest = LONG_MAX;
for (; it.current(); ++it) {
pZone = it.current();
// use the manhattenLength, a good enough of an appoximation here
lDistance = QABS( x - pZone->x() ) + QABS( y - pZone->y() );
// first to zero wins!
if ( lDistance < lClosest ) {
lClosest = lDistance;
pClosest = pZone;
}
}
// Okay, we found the closest city, but it might still be too far away.
if ( lClosest <= iTHRESHOLD ) {
showCity( pClosest );
cursor = pClosest;
}
}
void ZoneMap::showCity( ZoneField *city )
{
pLast = city;
// we'll use city and country a couple of times, get them to save some
// time
QString strCity = pLast->city();
QString strCountry = pLast->country();
// Display the time at this location by setting the environment timezone
// getting the current time [there] and then swapping back the variable
// so no one notices...
QString strSave;
char *p = getenv( "TZ" );
if ( p ) {
strSave = p;
}
// set the timezone :)
setenv( "TZ", strCountry + strCity, true );
lblCity->setText( strCity.replace( QRegExp("_"), " ") + "\n" +
TimeString::shortTime( ampm ) );
lblCity->setMinimumSize( lblCity->sizeHint() );
// undue our damage...
unsetenv( "TZ" );
if ( p )
setenv( "TZ", strSave, true );
// Now decide where to move the label, x & y can be reused
int tmpx, tmpy, x, y;
zoneToWin( pLast->x(), pLast->y(), tmpx, tmpy );
contentsToViewport(tmpx, tmpy, x, y);
if ( lblCity->width() > drawableW - x ) {
// oops... try putting it on the right
x = x - lblCity->width() - iLABELOFFSET;
} else {
// the default...
x += iLABELOFFSET;
}
if ( lblCity->height() > drawableH - y ) {
// move it up...
y = y - lblCity->height() - iLABELOFFSET;
} else if ( y < 0 ) {
// the city is actually off the screen...
// this only happens on the a zoom when you are near the top,
// a quick workaround..
y = iLABELOFFSET;
} else {
// the default
y += iLABELOFFSET;
}
// draw in the city and the label
if ( pRepaint ) {
int repx,
repy;
zoneToWin( pRepaint->x(), pRepaint->y(), repx, repy );
updateContents( repx - iCITYOFFSET, repy - iCITYOFFSET,
iCITYSIZE, iCITYSIZE );
}
updateContents( tmpx - iCITYOFFSET, tmpy - iCITYOFFSET, iCITYSIZE,
iCITYSIZE );
pRepaint = pLast;
lblCity->move( x, y );
lblCity->show();
}
void ZoneMap::resizeEvent( QResizeEvent *e )
{
// keep the zoom button down in the corner
QSize _size = e->size();
cmdZoom->move( _size.width() - cmdZoom->width(),
_size.height() - cmdZoom->height() );
if ( !bZoom ) {
drawableW = width() - 2 * frameWidth();
drawableH = height() - 2 * frameWidth();
makeMap( drawableW, drawableH );
resizeContents( drawableW, drawableH );
}
}
void ZoneMap::showZones( void ) const
{
// go through the zones in the list and just display the values...
QListIterator<ZoneField> itZone( zones );
for ( itZone.toFirst(); itZone.current(); ++itZone ) {
ZoneField *pZone = itZone.current();
pZone->showStructure();
}
}
QWidget* ZoneMap::selectionWidget( QWidget *parent) {
QWidget *returnWidget = new QWidget( parent );
QVBoxLayout *layout = new QVBoxLayout( returnWidget );
QHBox *hBox = new QHBox( returnWidget );
QListView *continentView = new QListView( hBox );
continentView->addColumn( tr("Continent") );
QWhatsThis::add( continentView, tr("Select a continent/country here, then select a city") );
connect ( continentView, SIGNAL( clicked ( QListViewItem * ) ), this, SLOT( slotGetCities( QListViewItem * ) ) );
QStringList continentList;
QListIterator<ZoneField> itZone( zones );
for ( itZone.toFirst(); itZone.current(); ++itZone ) {
ZoneField *pZone = itZone.current();
if ( continentList.contains( pZone->country() ) == 0 ) {
QString name;
QListViewItem *item;
if ( !(pZone->country().length() > 24) ) {
name = pZone->country().left(pZone->country().length()-1 );
} else {
name = pZone->country().left( 24 );
}
item = new QListViewItem( continentView, name, pZone->country() );
continentList.append( pZone->country() );
}
}
cityView = new QListView( hBox );
cityView->addColumn( tr("City") );
layout->addWidget( hBox );
return returnWidget;
}
void ZoneMap::slotGetCities( QListViewItem * contItem) {
cityView->clear();
selectedCont = contItem->text( 1 );
QListIterator<ZoneField> itZone( zones );
for ( itZone.toFirst(); itZone.current(); ++itZone ) {
ZoneField *pZone = itZone.current();
if ( pZone->country() == contItem->text( 1 ) ) {
QListViewItem *item;
item = new QListViewItem( cityView, pZone->city() );
connect ( cityView, SIGNAL( clicked ( QListViewItem* ) ), this, SLOT( slotCitySelected( QListViewItem* ) ) );
}
}
}
void ZoneMap::slotCitySelected( QListViewItem *cityItem ) {
if ( cityItem ) {
emit signalTz( selectedCont, cityItem->text( 0 ) );
}
}
void ZoneMap::drawCities( QPainter *p )
{
int x, y, j;
// draw in the cities
// for testing only as when you put it
// on the small screen it looks awful and not to mention useless
p->setPen( red );
QListIterator<ZoneField> itZone( zones );
for ( itZone.toFirst(), j = 0; itZone.current(); ++itZone, j++ ) {
ZoneField *pZone = itZone.current();
zoneToWin( pZone->x(), pZone->y(), x, y );
if ( x > wImg )
x = x - wImg;
p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE);
}
}
static void dayNight(QImage *pImage)
{
// create a mask the functions from sun.h
double dJulian,
dSunRad,
dSunDecl,
dSunRadius,
dSunLong;
int wImage = pImage->width(),
hImage = pImage->height(),
iStart,
iStop,
iMid,
relw,
i;
short wtab[ wImage ];
time_t tCurrent;
struct tm *pTm;
// get the position of the sun bassed on our current time...
tCurrent = time( NULL );
pTm = gmtime( &tCurrent );
dJulian = jtime( pTm );
sunpos( dJulian, 0, &dSunRad, &dSunDecl, &dSunRadius, &dSunLong );
// now get the projected illumination
projillum( wtab, wImage, hImage, dSunDecl );
relw = wImage - int( wImage * 0.0275 );
// draw the map, keeping in mind that we may go too far off the map...
iMid = ( relw * ( 24*60 - pTm->tm_hour * 60 - pTm->tm_min ) ) / ( 24*60 );
for ( i = 0; i < hImage; i++ ) {
if ( wtab[i] > 0 ) {
iStart = iMid - wtab[i];
iStop = iMid + wtab[i];
if ( iStart < 0 ) {
darken( pImage, iStop, wImage + iStart, i );
} else if ( iStop > wImage ) {
darken( pImage, iStop - wImage, iStart, i );
} else {
darken( pImage, 0, iStart, i );
darken( pImage, iStop, wImage, i );
}
} else {
darken( pImage, 0, wImage, i );
}
}
}
static inline void darken( QImage *pImage, int start, int stop, int row )
{
int colors,
j;
uchar *p;
// assume that the image is similar to the one we have...
colors = pImage->numColors() / 2;
p = pImage->scanLine( row );
for ( j = start; j <= stop; j++ ) {
if ( p[j] < colors )
p[j] += colors;
}
}
void ZoneMap::makeMap( int w, int h )
{
QImage imgOrig = Resource::loadImage( strMAP );
if ( imgOrig.isNull() ) {
QMessageBox::warning( this,
tr( "Couldn't Find Map" ),
tr( "<p>Couldn't load map: %1, exiting")
.arg( strMAP ) );
exit(-1);
}
// set up the color table for darkening...
imgOrig = imgOrig.convertDepth( 8 );
int numColors = imgOrig.numColors();
// double the colors
imgOrig.setNumColors( 2 * numColors );
// darken the new ones...
for ( int i = 0; i < numColors; i++ ) {
QRgb rgb = imgOrig.color( i );
imgOrig.setColor ( i + numColors, qRgb( 2 * qRed( rgb ) / 3,
2 * qGreen( rgb ) / 3, 2 * qBlue( rgb ) / 3 ) );
}
// else go one with making the map...
if ( bIllum ) {
// do a daylight mask
dayNight(&imgOrig);
}
// redo the width and height
wImg = w;
hImg = h;
ox = ( wImg / 2 ) - int( wImg * 0.0275 );
oy = hImg / 2;
pixCurr->convertFromImage( imgOrig.smoothScale(w, h),
QPixmap::ThresholdDither );
}
void ZoneMap::drawCity( QPainter *p, const ZoneField *pCity )
{
int x,
y;
p->setPen( red );
zoneToWin( pCity->x(), pCity->y(), x, y );
p->drawRect( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE );
}
void ZoneMap::drawContents( QPainter *p, int cx, int cy, int cw, int ch )
{
// if there is a need to resize, then do it...
// get our drawable area
drawableW = width() - 2 * frameWidth();
drawableH = height() - 2 * frameWidth();
int pixmapW = pixCurr->width(),
pixmapH = pixCurr->height();
if ( !bZoom && ( ( pixmapW != drawableW ) ||
( pixmapH != drawableH) ) ) {
makeMap( drawableW, drawableH );
}
// taken from the scrollview example...
int rowheight = pixCurr->height();
int toprow = cy / rowheight;
int bottomrow = ( cy + ch + rowheight - 1 ) / rowheight;
int colwidth = pixCurr->width();
int leftcol= cx / colwidth;
int rightcol= ( cx + cw + colwidth - 1 ) / colwidth;
for ( int r = toprow; r <= bottomrow; r++ ) {
int py = r * rowheight;
for ( int c = leftcol; c <= rightcol; c++ ) {
int px = c * colwidth;
p->drawPixmap( px, py, *pixCurr );
}
}
// Draw that city!
if ( pLast )
drawCity( p, pLast );
}
void ZoneMap::slotZoom( bool setZoom )
{
bZoom = setZoom;
if ( bZoom ) {
makeMap( 2 * wImg , 2 * hImg );
resizeContents( wImg, hImg );
} else {
makeMap( drawableW, drawableH );
resizeContents( drawableW, drawableH );
}
}
void ZoneMap::slotIllum( bool setIllum )
{
bIllum = !setIllum;
// make the map...
makeMap( pixCurr->width(), pixCurr->height() );
updateContents( 0, 0, wImg, hImg );
}
void ZoneMap::slotUpdate( void )
{
// recalculate the light, most people will never see this,
// but it is good to be complete
makeMap ( pixCurr->width(), pixCurr->height() );
updateContents( contentsX(), contentsY(), drawableW, drawableH );
}
void ZoneMap::slotRedraw( void )
{
// paint over that pesky city...
int x,
y;
if ( pRepaint ) {
pLast = 0;
zoneToWin(pRepaint->x(), pRepaint->y(), x, y);
updateContents( x - iCITYOFFSET, y - iCITYOFFSET, iCITYSIZE, iCITYSIZE);
pRepaint = 0;
}
}
void ZoneMap::changeClock( bool whichClock )
{
ampm = whichClock;
}
diff --git a/core/settings/light-and-power/light.cpp b/core/settings/light-and-power/light.cpp
index 60f7417..4baff8e 100644
--- a/core/settings/light-and-power/light.cpp
+++ b/core/settings/light-and-power/light.cpp
@@ -1,314 +1,313 @@
/*
This file is part of the OPIE Project
               =. Copyright (c) 2002 Maximilian Reiss <harlekin@handhelds.org>
             .=l. Copyright (c) 2002 Robert Griebl <sandman@handhelds.org>
           .>+-=
 _;:,     .>    :=|. This file is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This file 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 General
..}^=.=       =       ; Public License for more details.
++=   -.     .`     .:
 :     =  ...= . :.=- You should have received a copy of the GNU
 -.   .:....=;==+<; General Public License along with this file;
  -_. . .   )=.  = see the file COPYING. If not, write to the
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "light.h"
#include <qpe/config.h>
#include <qpe/power.h>
#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
#include <qpe/qcopenvelope_qws.h>
#endif
-#include <qpe/qpeapplication.h>
#include <qlabel.h>
#include <qcheckbox.h>
#include <qtabwidget.h>
#include <qslider.h>
#include <qspinbox.h>
#include <qpushbutton.h>
#include <qgroupbox.h>
#include <qcombobox.h>
#include <opie/odevice.h>
#include "sensor.h"
using namespace Opie;
LightSettings::LightSettings( QWidget* parent, const char* name, WFlags )
: LightSettingsBase( parent, name, false, WStyle_ContextHelp )
{
m_bres = ODevice::inst ( )-> displayBrightnessResolution ( );
m_cres = ODevice::inst ( )-> displayContrastResolution ( );
// check whether to show the light sensor stuff
if ( !ODevice::inst ( )-> hasLightSensor ( )) {
auto_brightness-> hide ( );
CalibrateLightSensor-> hide ( );
auto_brightness_ac-> hide ( );
CalibrateLightSensor_ac-> hide ( );
}
// check whether to show the contrast stuff
if (m_cres) {
GroupLight->setTitle(tr("Backlight && Contrast"));
GroupLight_ac->setTitle(GroupLight->title());
} else {
contrast->hide();
contrast_ac->hide();
}
// check whether to show the cpu frequency stuff
QStrList freq = ODevice::inst()->allowedCpuFrequencies();
if ( freq.count() ) {
frequency->insertStrList( freq );
frequency_ac->insertStrList( freq );
} else {
frequencyLabel->hide();
frequency->hide();
frequencyLabel_ac->hide();
frequency_ac->hide();
}
// check whether to show the hinge action stuff
if ( !ODevice::inst()->hasHingeSensor() ) {
closeHingeLabel->hide();
closeHingeAction->hide();
closeHingeLabel_ac->hide();
closeHingeAction_ac->hide();
}
Config config ( "apm" );
config. setGroup ( "Battery" );
// battery spinboxes
interval_dim-> setValue ( config. readNumEntry ( "Dim", 30 ));
interval_lightoff-> setValue ( config. readNumEntry ( "LightOff", 20 ));
interval_suspend-> setValue ( config. readNumEntry ( "Suspend", 60 ));
// battery check and slider
LcdOffOnly->setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
// CPU frequency
frequency->setCurrentItem( config.readNumEntry("Freq", 0) );
// hinge action
closeHingeAction->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) );
int bright = config. readNumEntry ( "Brightness", 127 );
int contr = m_oldcontrast = config. readNumEntry ( "Contrast", 127 );
brightness-> setTickInterval ( QMAX( 16, 256 / m_bres ));
brightness-> setLineStep ( QMAX( 1, 256 / m_bres ));
brightness-> setPageStep ( QMAX( 1, 256 / m_bres ));
brightness-> setValue ( bright );
if (m_cres) {
contrast-> setTickInterval ( QMAX( 16, 256 / m_cres ));
contrast-> setLineStep ( QMAX( 1, 256 / m_cres ));
contrast-> setPageStep ( QMAX( 1, 256 / m_cres ));
contrast-> setValue ( contr );
}
// light sensor
auto_brightness-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
m_sensordata = config. readListEntry ( "LightSensorData", ';' );
config. setGroup ( "AC" );
// ac spinboxes
interval_dim_ac-> setValue ( config. readNumEntry ( "Dim", 60 ));
interval_lightoff_ac-> setValue ( config. readNumEntry ( "LightOff", 120 ));
interval_suspend_ac-> setValue ( config. readNumEntry ( "Suspend", 0 ));
// ac check and slider
LcdOffOnly_ac-> setChecked ( config. readBoolEntry ( "LcdOffOnly", false ));
// CPU frequency
frequency_ac->setCurrentItem( config.readNumEntry("Freq", 0) );
// hinge action
closeHingeAction_ac->setCurrentItem( config.readNumEntry("CloseHingeAction", 0) );
bright = config. readNumEntry ( "Brightness", 255 );
brightness_ac-> setTickInterval ( QMAX( 16, 256 / m_bres ));
brightness_ac-> setLineStep ( QMAX( 1, 256 / m_bres ));
brightness_ac-> setPageStep ( QMAX( 1, 256 / m_bres ));
brightness_ac-> setValue ( bright );
if (m_cres) {
contr = config. readNumEntry ( "Contrast", 127);
contrast_ac-> setTickInterval ( QMAX( 16, 256 / m_cres ));
contrast_ac-> setLineStep ( QMAX( 1, 256 / m_cres ));
contrast_ac-> setPageStep ( QMAX( 1, 256 / m_cres ));
contrast_ac-> setValue ( contr );
}
// light sensor
auto_brightness_ac-> setChecked ( config. readBoolEntry ( "LightSensor", false ));
m_sensordata_ac = config. readListEntry ( "LightSensorData", ';' );
// warnings
config. setGroup ( "Warnings" );
warnintervalBox-> setValue ( config. readNumEntry ( "checkinterval", 10000 ) / 1000 );
lowSpinBox-> setValue ( config. readNumEntry ( "powerverylow", 10 ) );
criticalSpinBox-> setValue ( config. readNumEntry ( "powercritical", 5 ) );
m_resettimer = new QTimer ( this );
connect ( m_resettimer, SIGNAL( timeout ( )), this, SLOT( resetBacklight ( )));
if ( PowerStatusManager::readStatus ( ). acStatus ( ) != PowerStatus::Online ) {
tabs-> setCurrentPage ( 0 );
}
else {
tabs-> setCurrentPage ( 1 );
}
connect ( brightness, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
connect ( brightness_ac, SIGNAL( valueChanged ( int )), this, SLOT( setBacklight ( int )));
if (m_cres) {
connect ( contrast, SIGNAL( valueChanged ( int )), this, SLOT( setContrast ( int )));
connect ( contrast_ac, SIGNAL( valueChanged ( int )), this, SLOT( setContrast ( int )));
}
connect( frequency, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) );
connect( frequency_ac, SIGNAL( activated(int) ), this, SLOT( setFrequency(int) ) );
connect( closeHingeAction, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) );
connect( closeHingeAction_ac, SIGNAL( activated(int) ), this, SLOT( setCloseHingeAction(int) ) );
}
LightSettings::~LightSettings ( )
{
}
void LightSettings::calibrateSensor ( )
{
Sensor *s = new Sensor ( m_sensordata, this );
connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int )));
QPEApplication::execDialog( s );
delete s;
}
void LightSettings::calibrateSensorAC ( )
{
Sensor *s = new Sensor ( m_sensordata_ac, this );
connect ( s, SIGNAL( viewBacklight ( int )), this, SLOT( setBacklight ( int )));
QPEApplication::execDialog ( s );
delete s;
}
void LightSettings::setBacklight ( int bright )
{
QCopEnvelope e ( "QPE/System", "setBacklight(int)" );
e << bright;
if ( bright != -1 ) {
m_resettimer-> stop ( );
m_resettimer-> start ( 4000, true );
}
}
void LightSettings::setContrast ( int contr )
{
if (contr == -1) contr = m_oldcontrast;
ODevice::inst ( )-> setDisplayContrast(contr);
}
void LightSettings::setFrequency ( int index )
{
qWarning("LightSettings::setFrequency(%d)", index);
ODevice::inst ( )-> setCurrentCpuFrequency(index);
}
void LightSettings::resetBacklight ( )
{
setBacklight ( -1 );
setContrast ( -1 );
}
void LightSettings::setCloseHingeAction ( int index )
{
qWarning("LightSettings::setCloseHingeStatus(%d)", index);
}
void LightSettings::accept ( )
{
Config config ( "apm" );
// bat
config. setGroup ( "Battery" );
config. writeEntry ( "LcdOffOnly", LcdOffOnly-> isChecked ( ));
config. writeEntry ( "Dim", interval_dim-> value ( ));
config. writeEntry ( "LightOff", interval_lightoff-> value ( ));
config. writeEntry ( "Suspend", interval_suspend-> value ( ));
config. writeEntry ( "Brightness", brightness-> value () );
if (m_cres)
config. writeEntry ( "Contrast", contrast-> value () );
config. writeEntry ( "Freq", frequency->currentItem() );
config. writeEntry ( "CloseHingeAction", closeHingeAction->currentItem() );
// ac
config. setGroup ( "AC" );
config. writeEntry ( "LcdOffOnly", LcdOffOnly_ac-> isChecked ( ));
config. writeEntry ( "Dim", interval_dim_ac-> value ( ));
config. writeEntry ( "LightOff", interval_lightoff_ac-> value ( ));
config. writeEntry ( "Suspend", interval_suspend_ac-> value ( ));
config. writeEntry ( "Brightness", brightness_ac-> value () );
if (m_cres)
config. writeEntry ( "Contrast", contrast_ac-> value () );
config. writeEntry ( "Freq", frequency_ac->currentItem() );
config. writeEntry ( "CloseHingeAction", closeHingeAction_ac->currentItem() );
// only make light sensor stuff appear if the unit has a sensor
if ( ODevice::inst ( )-> hasLightSensor ( )) {
config. setGroup ( "Battery" );
config. writeEntry ( "LightSensor", auto_brightness->isChecked() );
config. writeEntry ( "LightSensorData", m_sensordata, ';' );
config. setGroup ( "AC" );
config. writeEntry ( "LightSensor", auto_brightness_ac->isChecked() );
config. writeEntry ( "LightSensorData", m_sensordata_ac, ';' );
}
// advanced
config. setGroup ( "Warnings" );
config. writeEntry ( "check_interval", warnintervalBox-> value ( ) * 1000 );
config. writeEntry ( "power_verylow", lowSpinBox-> value ( ));
config. writeEntry ( "power_critical", criticalSpinBox-> value ( ));
config. write ( );
// notify the launcher
{
QCopEnvelope e ( "QPE/System", "reloadPowerWarnSettings()" );
}
{
QCopEnvelope e ( "QPE/System", "setScreenSaverInterval(int)" );
e << -1;
}
LightSettingsBase::accept ( );
}
void LightSettings::done ( int r )
{
m_resettimer-> stop ( );
resetBacklight ( );
LightSettingsBase::done ( r );
close ( );
}
diff --git a/libqtaux/ocolorbutton.cpp b/libqtaux/ocolorbutton.cpp
index d2ad873..fd3f963 100644
--- a/libqtaux/ocolorbutton.cpp
+++ b/libqtaux/ocolorbutton.cpp
@@ -1,150 +1,147 @@
/*
This file is part of the Opie Project
Copyright (C) Robert Griebl <sandman@handhelds.org>
=. Copyright (C) The Opie Team <opie-devel@handhelds.org>
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "ocolorpopupmenu.h"
#include "ocolorbutton.h"
/* OPIE */
-#include <qpe/resource.h>
/* QT */
-#include <qcolor.h>
-#include <qpixmap.h>
#include <qimage.h>
using namespace Opie;
struct OColorButtonPrivate
{
QPopupMenu *m_menu;
QColor m_color;
};
/**
* This concstructs a Color Button with @param color as the start color
* It'll use a OColorPopupMenu internally
*
* @param parent The parent of the Color Button
* @param color The color from where to start on
* @param name @see QObject
*/
OColorButton::OColorButton ( QWidget *parent, const QColor &color, const char *name )
: QPushButton ( parent, name )
{
d = new OColorButtonPrivate;
d-> m_menu = new OColorPopupMenu ( color, 0, 0 );
setPopup ( d-> m_menu );
// setPopupDelay ( 0 );
connect ( d-> m_menu, SIGNAL( colorSelected ( const QColor & )), this, SLOT( updateColor ( const QColor & )));
updateColor ( color );
QSize s = sizeHint ( ) + QSize ( 12, 0 );
setMinimumSize ( s );
setMaximumSize ( s. width ( ) * 2, s. height ( ));
}
/**
* This destructs the object
*/
OColorButton::~OColorButton ( )
{
delete d;
}
/**
* @return Returns the current color of the button
*/
QColor OColorButton::color ( ) const
{
return d-> m_color;
}
/**
* This method sets the color of the button
* @param c The color to be set.
*/
void OColorButton::setColor ( const QColor &c )
{
updateColor ( c );
}
/**
* @internal
*/
void OColorButton::updateColor ( const QColor &c )
{
d-> m_color = c;
QImage img ( 16, 16, 32 );
img. fill ( 0 );
int r, g, b;
c. rgb ( &r, &g, &b );
int w = img. width ( );
int h = img. height ( );
int dx = w * 20 / 100; // 15%
int dy = h * 20 / 100;
for ( int y = 0; y < h; y++ )
{
for ( int x = 0; x < w; x++ )
{
double alpha = 1.0;
if ( x < dx )
alpha *= ( double ( x + 1 ) / dx );
else if ( x >= w - dx )
alpha *= ( double ( w - x ) / dx );
if ( y < dy )
alpha *= ( double ( y + 1 ) / dy );
else if ( y >= h - dy )
alpha *= ( double ( h - y ) / dy );
int a = int ( alpha * 255.0 );
if ( a < 0 )
a = 0;
if ( a > 255 )
a = 255;
img. setPixel ( x, y, qRgba ( r, g, b, a ));
}
}
img. setAlphaBuffer ( true );
QPixmap pix;
pix. convertFromImage ( img );
setPixmap ( pix );
emit colorSelected ( c );
}
diff --git a/libqtaux/ocolorpopupmenu.cpp b/libqtaux/ocolorpopupmenu.cpp
index 6c5f99c..c5b2b88 100644
--- a/libqtaux/ocolorpopupmenu.cpp
+++ b/libqtaux/ocolorpopupmenu.cpp
@@ -1,176 +1,175 @@
/*
                This file is part of the Opie Project
              Copyright (c) 2002 S. Prud'homme <prudhomme@laposte.net>
              Dan Williams <williamsdr@acm.org>
=.
.=l.
           .>+-=
 _;:,     .>    :=|. This program is free software; you can
.> <`_,   >  .   <= redistribute it and/or modify it under
:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
.="- .-=="i,     .._ License as published by the Free Software
 - .   .-<_>     .<> Foundation; either version 2 of the License,
     ._= =}       : or (at your option) any later version.
    .%`+i>       _;_.
    .i_,=:_.      -<s. This program is distributed in the hope that
     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
    : ..    .:,     . . . without even the implied warranty of
    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
..}^=.=       =       ; Library General Public License for more
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include "ocolorpopupmenu.h"
#include "qcolordialog.h"
/* QT */
-#include <qaction.h>
#include <qlayout.h>
#include <qpainter.h>
using namespace Opie;
OColorPanelButton::OColorPanelButton( const QColor& color, QWidget* parent, const char* name )
: QFrame( parent, name )
{
m_color = color;
setFixedSize( 16, 16 );
setActive( FALSE );
}
OColorPanelButton::~OColorPanelButton()
{
}
void OColorPanelButton::setActive( bool active )
{
m_active = active;
if ( m_active ) {
setFrameStyle( Panel | Sunken );
} else {
setFrameStyle( NoFrame );
}
}
void OColorPanelButton::enterEvent( QEvent* )
{
if ( !m_active ) {
setFrameStyle( Panel | Sunken );
}
}
void OColorPanelButton::leaveEvent( QEvent* )
{
if ( !m_active ) {
setFrameStyle( NoFrame );
}
}
void OColorPanelButton::paintEvent( QPaintEvent* e )
{
QFrame::paintEvent( e );
QPainter painter;
painter.begin( this );
painter.fillRect( 2, 2, 12, 12, m_color );
painter.setPen( Qt::black );
painter.drawRect( 2, 2, 12, 12 );
painter.end();
}
void OColorPanelButton::mouseReleaseEvent( QMouseEvent* )
{
emit selected( m_color );
}
OColorPopupMenu::OColorPopupMenu( const QColor& color, QWidget* parent, const char* name )
: QPopupMenu( parent, name )
{
m_color = color;
colorPanel = new QWidget( this );
colorLayout = new QGridLayout(colorPanel, 5, 6);
addColor(QColor(255, 255, 255), 0, 1);
addColor(QColor(192, 192, 192), 0, 2);
addColor(QColor(128, 128, 128), 0, 3);
addColor(QColor(64, 64, 64), 0, 4);
addColor(QColor(0, 0, 0), 0, 5);
addColor(QColor(255, 0, 0), 1, 0);
addColor(QColor(255, 128, 0), 1, 1);
addColor(QColor(255, 255, 0), 1, 2);
addColor(QColor(128, 255, 0), 1, 3);
addColor(QColor(0, 255, 0), 1, 4);
addColor(QColor(0, 255, 128), 1, 5);
addColor(QColor(128, 0, 0), 2, 0);
addColor(QColor(128, 64, 0), 2, 1);
addColor(QColor(128, 128, 0), 2, 2);
addColor(QColor(64, 128, 0), 2, 3);
addColor(QColor(0, 128, 0), 2, 4);
addColor(QColor(0, 128, 64), 2, 5);
addColor(QColor(0, 255, 255), 3, 0);
addColor(QColor(0, 128, 255), 3, 1);
addColor(QColor(0, 0, 255), 3, 2);
addColor(QColor(128, 0, 255), 3, 3);
addColor(QColor(255, 0, 255), 3, 4);
addColor(QColor(255, 0, 128), 3, 5);
addColor(QColor(0, 128, 128), 4, 0);
addColor(QColor(0, 64, 128), 4, 1);
addColor(QColor(0, 0, 128), 4, 2);
addColor(QColor(64, 0, 128), 4, 3);
addColor(QColor(128, 0, 128), 4, 4);
addColor(QColor(128, 0, 64), 4, 5);
insertItem( colorPanel );
insertSeparator();
insertItem(tr("More"),this,SLOT( moreColorClicked()));
/*
QAction* chooseColorAction = new QAction( tr( "More" ), tr( "More..." ), 0, colorPanel, "More" );
connect( chooseColorAction, SIGNAL( activated() ), this, SLOT( moreColorClicked() ) );
chooseColorAction->addTo( this );
*/
activateItemAt( 0 );
}
OColorPopupMenu::~OColorPopupMenu()
{
}
void OColorPopupMenu::addColor( const QColor& color, int row, int col )
{
OColorPanelButton* panelButton = new OColorPanelButton( color, colorPanel );
connect( panelButton, SIGNAL( selected( const QColor& ) ), this, SLOT( buttonSelected( const QColor& ) ) );
colorLayout->addWidget( panelButton, row, col );
}
void OColorPopupMenu::buttonSelected( const QColor& color )
{
m_color = color;
emit colorSelected( color );
hide();
}
void OColorPopupMenu::moreColorClicked()
{
QColor color = QColorDialog::getColor( m_color );
m_color = color;
emit colorSelected( color );
hide();
}
diff --git a/libqtaux/qcolordialog.cpp b/libqtaux/qcolordialog.cpp
index b960b04..907c2aa 100644
--- a/libqtaux/qcolordialog.cpp
+++ b/libqtaux/qcolordialog.cpp
@@ -1,1587 +1,1585 @@
/****************************************************************************
** $Id$
**
** Implementation of QColorDialog class
**
** Created : 990222
**
** Copyright (C) 1999-2000 Trolltech AS. All rights reserved.
**
** This file is part of the dialogs module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "qcolordialog.h"
#include "qpainter.h"
#include "qlayout.h"
#include "qlabel.h"
#include "qpushbutton.h"
#include "qlineedit.h"
#include "qimage.h"
#include "qpixmap.h"
#include "qdrawutil.h"
#include "qvalidator.h"
-#include "qdragobject.h"
#include "qapplication.h"
-#include "qdragobject.h"
//////////// QWellArray BEGIN
#include "qobjectdict.h"
//
// W A R N I N G
// -------------
//
// This file is not part of the Qt API. It exists for the convenience
// of qwellarray.cpp and qcolordialog.cpp.
// This header file may change from version to version without notice,
// or even be removed.
//
//
#include "qtableview.h"
struct QWellArrayData;
class QWellArray : public QTableView
{
Q_OBJECT
Q_PROPERTY( int numCols READ numCols )
Q_PROPERTY( int numRows READ numRows )
Q_PROPERTY( int selectedColumn READ selectedColumn )
Q_PROPERTY( int selectedRow READ selectedRow )
public:
QWellArray( QWidget *parent=0, const char *name=0, bool popup = FALSE );
~QWellArray() {}
QString cellContent( int row, int col ) const;
// ### Paul !!! virtual void setCellContent( int row, int col, const QString &);
// ##### Obsolete since not const
int numCols() { return nCols; }
int numRows() { return nRows; }
int numCols() const { return nCols; }
int numRows() const { return nRows; }
// ##### Obsolete since not const
int selectedColumn() { return selCol; }
int selectedRow() { return selRow; }
int selectedColumn() const { return selCol; }
int selectedRow() const { return selRow; }
virtual void setSelected( int row, int col );
void setCellSize( int w, int h ) { setCellWidth(w);setCellHeight( h ); }
QSize sizeHint() const;
virtual void setDimension( int rows, int cols );
virtual void setCellBrush( int row, int col, const QBrush & );
QBrush cellBrush( int row, int col );
signals:
void selected( int row, int col );
protected:
virtual void setCurrent( int row, int col );
virtual void drawContents( QPainter *, int row, int col, const QRect& );
void drawContents( QPainter * );
void paintCell( QPainter*, int row, int col );
void mousePressEvent( QMouseEvent* );
void mouseReleaseEvent( QMouseEvent* );
void mouseMoveEvent( QMouseEvent* );
void keyPressEvent( QKeyEvent* );
void focusInEvent( QFocusEvent* );
void focusOutEvent( QFocusEvent* );
private:
int curRow;
int curCol;
int selRow;
int selCol;
int nCols;
int nRows;
bool smallStyle;
QWellArrayData *d;
private: // Disabled copy constructor and operator=
#if defined(Q_DISABLE_COPY)
QWellArray( const QWellArray & );
QWellArray& operator=( const QWellArray & );
#endif
};
// non-interface ...
struct QWellArrayData {
QBrush *brush;
};
// NOT REVISED
/* WARNING, NOT
\class QWellArray qwellarray_p.h
\brief ....
....
\ingroup advanced
*/
QWellArray::QWellArray( QWidget *parent, const char * name, bool popup )
: QTableView( parent, name,
popup ? (WStyle_Customize|WStyle_Tool|WStyle_NoBorder) : 0 )
{
d = 0;
setFocusPolicy( StrongFocus );
setBackgroundMode( PaletteButton );
nCols = 7;
nRows = 7;
int w = 24; // cell width
int h = 21; // cell height
smallStyle = popup;
if ( popup ) {
w = h = 18;
if ( style() == WindowsStyle )
setFrameStyle( QFrame::WinPanel | QFrame::Raised );
else
setFrameStyle( QFrame::Panel | QFrame::Raised );
setMargin( 1 );
setLineWidth( 2 );
}
setNumCols( nCols );
setNumRows( nRows );
setCellWidth( w );
setCellHeight( h );
curCol = 0;
curRow = 0;
selCol = -1;
selRow = -1;
if ( smallStyle )
setMouseTracking( TRUE );
setOffset( 5 , 10 );
resize( sizeHint() );
}
QSize QWellArray::sizeHint() const
{
constPolish();
int f = frameWidth() * 2;
int w = nCols * cellWidth() + f;
int h = nRows * cellHeight() + f;
return QSize( w, h );
}
void QWellArray::paintCell( QPainter* p, int row, int col )
{
int w = cellWidth( col ); // width of cell in pixels
int h = cellHeight( row ); // height of cell in pixels
int b = 1;
if ( !smallStyle )
b = 3;
const QColorGroup & g = colorGroup();
p->setPen( QPen( black, 0, SolidLine ) );
if ( !smallStyle && row ==selRow && col == selCol &&
style() != MotifStyle ) {
int n = 2;
p->drawRect( n, n, w-2*n, h-2*n );
}
if ( style() == WindowsStyle ) {
qDrawWinPanel( p, b, b , w - 2*b, h - 2*b,
g, TRUE );
b += 2;
} else {
if ( smallStyle ) {
qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
g, TRUE, 2 );
b += 2;
} else {
int t = ( row == selRow && col == selCol ) ? 2 : 0;
b -= t;
qDrawShadePanel( p, b, b , w - 2*b, h - 2*b,
g, TRUE, 2 );
b += 2 + t;
}
}
if ( (row == curRow) && (col == curCol) ) {
if ( smallStyle ) {
p->setPen ( white );
p->drawRect( 1, 1, w-2, h-2 );
p->setPen ( black );
p->drawRect( 0, 0, w, h );
p->drawRect( 2, 2, w-4, h-4 );
b = 3;
} else if ( hasFocus() ) {
style().drawFocusRect(p, QRect(0,0,w,h), g );
}
}
drawContents( p, row, col, QRect(b, b, w - 2*b, h - 2*b) );
}
/*!
Pass-through to QTableView::drawContents() to avoid hiding.
*/
void QWellArray::drawContents( QPainter *p )
{
QTableView::drawContents(p);
}
/*!
Reimplement this function to change the contents of the well array.
*/
void QWellArray::drawContents( QPainter *p, int row, int col, const QRect &r )
{
if ( d ) {
p->fillRect( r, d->brush[row*nCols+col] );
} else {
p->fillRect( r, white );
p->setPen( black );
p->drawLine( r.topLeft(), r.bottomRight() );
p->drawLine( r.topRight(), r.bottomLeft() );
}
}
/*\reimp
*/
void QWellArray::mousePressEvent( QMouseEvent* e )
{
// The current cell marker is set to the cell the mouse is pressed
// in.
QPoint pos = e->pos();
setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
}
/*\reimp
*/
void QWellArray::mouseReleaseEvent( QMouseEvent* )
{
// The current cell marker is set to the cell the mouse is clicked
// in.
setSelected( curRow, curCol );
}
/*\reimp
*/
void QWellArray::mouseMoveEvent( QMouseEvent* e )
{
// The current cell marker is set to the cell the mouse is
// clicked in.
if ( smallStyle ) {
QPoint pos = e->pos();
setCurrent( findRow( pos.y() ), findCol( pos.x() ) );
}
}
/*
Sets the cell currently having the focus. This is not necessarily
the same as the currently selected cell.
*/
void QWellArray::setCurrent( int row, int col )
{
if ( (curRow == row) && (curCol == col) )
return;
if ( row < 0 || col < 0 )
row = col = -1;
int oldRow = curRow;
int oldCol = curCol;
curRow = row;
curCol = col;
updateCell( oldRow, oldCol );
updateCell( curRow, curCol );
}
/*!
Sets the currently selected cell to \a row, \a col. If \a row or \a
col are less than zero, the current cell is unselected.
Does not set the position of the focus indicator.
*/
void QWellArray::setSelected( int row, int col )
{
if ( (selRow == row) && (selCol == col) )
return;
int oldRow = selRow;
int oldCol = selCol;
if ( row < 0 || col < 0 )
row = col = -1;
selCol = col;
selRow = row;
updateCell( oldRow, oldCol );
updateCell( selRow, selCol );
if ( row >= 0 )
emit selected( row, col );
if ( isVisible() && parentWidget() && parentWidget()->inherits("QPopupMenu") )
parentWidget()->close();
}
/*!\reimp
*/
void QWellArray::focusInEvent( QFocusEvent* )
{
updateCell( curRow, curCol );
}
/*!
Sets the size of the well array to be \c rows cells by \c cols.
Resets any brush info set by setCellBrush().
Must be called by reimplementors.
*/
void QWellArray::setDimension( int rows, int cols )
{
nRows = rows;
nCols = cols;
if ( d ) {
if ( d->brush )
delete[] d->brush;
delete d;
d = 0;
}
setNumCols( nCols );
setNumRows( nRows );
}
void QWellArray::setCellBrush( int row, int col, const QBrush &b )
{
if ( !d ) {
d = new QWellArrayData;
d->brush = new QBrush[nRows*nCols];
}
if ( row >= 0 && row < nRows && col >= 0 && col < nCols )
d->brush[row*nCols+col] = b;
#ifdef CHECK_RANGE
else
qWarning( "QWellArray::setCellBrush( %d, %d ) out of range", row, col );
#endif
}
/*!
Returns the brush set for the cell at \a row, \a col. If no brush is set,
\c NoBrush is returned.
*/
QBrush QWellArray::cellBrush( int row, int col )
{
if ( d && row >= 0 && row < nRows && col >= 0 && col < nCols )
return d->brush[row*nCols+col];
return NoBrush;
}
/*!\reimp
*/
void QWellArray::focusOutEvent( QFocusEvent* )
{
updateCell( curRow, curCol );
}
/*\reimp
*/
void QWellArray::keyPressEvent( QKeyEvent* e )
{
switch( e->key() ) { // Look at the key code
case Key_Left: // If 'left arrow'-key,
if( curCol > 0 ) { // and cr't not in leftmost col
setCurrent( curRow, curCol - 1); // set cr't to next left column
int edge = leftCell(); // find left edge
if ( curCol < edge ) // if we have moved off edge,
setLeftCell( edge - 1 ); // scroll view to rectify
}
break;
case Key_Right: // Correspondingly...
if( curCol < numCols()-1 ) {
setCurrent( curRow, curCol + 1);
int edge = lastColVisible();
if ( curCol >= edge )
setLeftCell( leftCell() + 1 );
}
break;
case Key_Up:
if( curRow > 0 ) {
setCurrent( curRow - 1, curCol);
int edge = topCell();
if ( curRow < edge )
setTopCell( edge - 1 );
} else if ( smallStyle )
focusNextPrevChild( FALSE );
break;
case Key_Down:
if( curRow < numRows()-1 ) {
setCurrent( curRow + 1, curCol);
int edge = lastRowVisible();
if ( curRow >= edge )
setTopCell( topCell() + 1 );
} else if ( smallStyle )
focusNextPrevChild( TRUE );
break;
case Key_Space:
case Key_Return:
case Key_Enter:
setSelected( curRow, curCol );
break;
default: // If not an interesting key,
e->ignore(); // we don't accept the event
return;
}
}
//////////// QWellArray END
static bool initrgb = FALSE;
static QRgb stdrgb[6*8];
static QRgb cusrgb[2*8];
static void initRGB()
{
if ( initrgb )
return;
initrgb = TRUE;
int i = 0;
for ( int g = 0; g < 4; g++ )
for ( int r = 0; r < 4; r++ )
for ( int b = 0; b < 3; b++ )
stdrgb[i++] = qRgb( r*255/3, g*255/3, b*255/2 );
for ( i = 0; i < 2*8; i++ )
cusrgb[i] = qRgb(0xff,0xff,0xff);
}
/*!
Returns the number of custom colors supported by
QColorDialog. All color dialogs share the same custom colors.
*/
int QColorDialog::customCount()
{
return 2*8;
}
/*!
Returns custom color number \a i as a QRgb.
*/
QRgb QColorDialog::customColor( int i )
{
initRGB();
if ( i < 0 || i >= customCount() ) {
#ifdef CHECK_RANGE
qWarning( "QColorDialog::customColor() index %d out of range", i );
#endif
i = 0;
}
return cusrgb[i];
}
/*!
Sets custom color number \a i to the QRgb value \a c.
*/
void QColorDialog::setCustomColor( int i, QRgb c )
{
initRGB();
if ( i < 0 || i >= customCount() ) {
#ifdef CHECK_RANGE
qWarning( "QColorDialog::customColor() index %d out of range", i );
#endif
return;
}
cusrgb[i] = c;
}
static inline void rgb2hsv( QRgb rgb, int&h, int&s, int&v )
{
QColor c;
c.setRgb( rgb );
c.getHsv(h,s,v);
}
class QColorWell : public QWellArray
{
public:
QColorWell( QWidget *parent, int r, int c, QRgb *vals )
:QWellArray( parent, "" ), values( vals ), mousePressed( FALSE ), oldCurrent( -1, -1 )
{ setDimension(r,c); setWFlags( WResizeNoErase ); }
QSizePolicy sizePolicy() const;
protected:
void drawContents( QPainter *, int row, int col, const QRect& );
void drawContents( QPainter *p ) { QWellArray::drawContents(p); }
void mousePressEvent( QMouseEvent *e );
void mouseMoveEvent( QMouseEvent *e );
void mouseReleaseEvent( QMouseEvent *e );
#ifndef QT_NO_DRAGANDDROP
void dragEnterEvent( QDragEnterEvent *e );
void dragLeaveEvent( QDragLeaveEvent *e );
void dragMoveEvent( QDragMoveEvent *e );
void dropEvent( QDropEvent *e );
#endif
private:
QRgb *values;
bool mousePressed;
QPoint pressPos;
QPoint oldCurrent;
};
QSizePolicy QColorWell::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum );
}
void QColorWell::drawContents( QPainter *p, int row, int col, const QRect &r )
{
int i = row + col*numRows();
p->fillRect( r, QColor( values[i] ) );
}
void QColorWell::mousePressEvent( QMouseEvent *e )
{
oldCurrent = QPoint( selectedRow(), selectedColumn() );
QWellArray::mousePressEvent( e );
mousePressed = TRUE;
pressPos = e->pos();
}
void QColorWell::mouseMoveEvent( QMouseEvent *e )
{
QWellArray::mouseMoveEvent( e );
#ifndef QT_NO_DRAGANDDROP
if ( !mousePressed )
return;
if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
setCurrent( oldCurrent.x(), oldCurrent.y() );
int i = findRow( e->y() ) + findCol( e->x() ) * numRows();
QColor col( values[ i ] );
QColorDrag *drg = new QColorDrag( col, this );
QPixmap pix( cellWidth(), cellHeight() );
pix.fill( col );
QPainter p( &pix );
p.drawRect( 0, 0, pix.width(), pix.height() );
p.end();
drg->setPixmap( pix );
mousePressed = FALSE;
drg->dragCopy();
}
#endif
}
#ifndef QT_NO_DRAGANDDROP
void QColorWell::dragEnterEvent( QDragEnterEvent *e )
{
setFocus();
if ( QColorDrag::canDecode( e ) )
e->accept();
else
e->ignore();
}
void QColorWell::dragLeaveEvent( QDragLeaveEvent * )
{
if ( hasFocus() )
parentWidget()->setFocus();
}
void QColorWell::dragMoveEvent( QDragMoveEvent *e )
{
if ( QColorDrag::canDecode( e ) ) {
setCurrent( findRow( e->pos().y() ), findCol( e->pos().x() ) );
e->accept();
} else
e->ignore();
}
void QColorWell::dropEvent( QDropEvent *e )
{
if ( QColorDrag::canDecode( e ) ) {
int i = findRow( e->pos().y() ) + findCol( e->pos().x() ) * numRows();
QColor col;
QColorDrag::decode( e, col );
values[ i ] = col.rgb();
repaint( FALSE );
e->accept();
} else {
e->ignore();
}
}
#endif // QT_NO_DRAGANDDROP
void QColorWell::mouseReleaseEvent( QMouseEvent *e )
{
if ( !mousePressed )
return;
QWellArray::mouseReleaseEvent( e );
mousePressed = FALSE;
}
class QColorPicker : public QFrame
{
Q_OBJECT
public:
QColorPicker(QWidget* parent=0, const char* name=0);
~QColorPicker();
public slots:
void setCol( int h, int s );
signals:
void newCol( int h, int s );
protected:
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
void drawContents(QPainter* p);
void mouseMoveEvent( QMouseEvent * );
void mousePressEvent( QMouseEvent * );
private:
int hue;
int sat;
QPoint colPt();
int huePt( const QPoint &pt );
int satPt( const QPoint &pt );
void setCol( const QPoint &pt );
QPixmap *pix;
};
static int pWidth = 200;
static int pHeight = 200;
class QColorLuminancePicker : public QWidget
{
Q_OBJECT
public:
QColorLuminancePicker(QWidget* parent=0, const char* name=0);
~QColorLuminancePicker();
public slots:
void setCol( int h, int s, int v );
void setCol( int h, int s );
signals:
void newHsv( int h, int s, int v );
protected:
// QSize sizeHint() const;
// QSizePolicy sizePolicy() const;
void paintEvent( QPaintEvent*);
void mouseMoveEvent( QMouseEvent * );
void mousePressEvent( QMouseEvent * );
private:
enum { foff = 3, coff = 4 }; //frame and contents offset
int val;
int hue;
int sat;
int y2val( int y );
int val2y( int val );
void setVal( int v );
QPixmap *pix;
};
int QColorLuminancePicker::y2val( int y )
{
int d = height() - 2*coff - 1;
return 255 - (y - coff)*255/d;
}
int QColorLuminancePicker::val2y( int v )
{
int d = height() - 2*coff - 1;
return coff + (255-v)*d/255;
}
QColorLuminancePicker::QColorLuminancePicker(QWidget* parent,
const char* name)
:QWidget( parent, name )
{
hue = 100; val = 100; sat = 100;
pix = 0;
// setBackgroundMode( NoBackground );
}
QColorLuminancePicker::~QColorLuminancePicker()
{
delete pix;
}
void QColorLuminancePicker::mouseMoveEvent( QMouseEvent *m )
{
setVal( y2val(m->y()) );
}
void QColorLuminancePicker::mousePressEvent( QMouseEvent *m )
{
setVal( y2val(m->y()) );
}
void QColorLuminancePicker::setVal( int v )
{
if ( val == v )
return;
val = QMAX( 0, QMIN(v,255));
delete pix; pix=0;
repaint( FALSE ); //###
emit newHsv( hue, sat, val );
}
//receives from a hue,sat chooser and relays.
void QColorLuminancePicker::setCol( int h, int s )
{
setCol( h, s, val );
emit newHsv( h, s, val );
}
void QColorLuminancePicker::paintEvent( QPaintEvent * )
{
int w = width() - 5;
QRect r( 0, foff, w, height() - 2*foff );
int wi = r.width() - 2;
int hi = r.height() - 2;
if ( !pix || pix->height() != hi || pix->width() != wi ) {
delete pix;
QImage img( wi, hi, 32 );
int y;
for ( y = 0; y < hi; y++ ) {
QColor c( hue, sat, y2val(y+coff), QColor::Hsv );
QRgb r = c.rgb();
int x;
for ( x = 0; x < wi; x++ )
img.setPixel( x, y, r );
}
pix = new QPixmap;
pix->convertFromImage(img);
}
QPainter p(this);
p.drawPixmap( 1, coff, *pix );
QColorGroup g = colorGroup();
qDrawShadePanel( &p, r, g, TRUE );
p.setPen( g.foreground() );
p.setBrush( g.foreground() );
QPointArray a;
int y = val2y(val);
a.setPoints( 3, w, y, w+5, y+5, w+5, y-5 );
erase( w, 0, 5, height() );
p.drawPolygon( a );
}
void QColorLuminancePicker::setCol( int h, int s , int v )
{
val = v;
hue = h;
sat = s;
delete pix; pix=0;
repaint( FALSE );//####
}
QPoint QColorPicker::colPt()
{ return QPoint( (360-hue)*(pWidth-1)/360, (255-sat)*(pHeight-1)/255 ); }
int QColorPicker::huePt( const QPoint &pt )
{ return 360 - pt.x()*360/(pWidth-1); }
int QColorPicker::satPt( const QPoint &pt )
{ return 255 - pt.y()*255/(pHeight-1) ; }
void QColorPicker::setCol( const QPoint &pt )
{ setCol( huePt(pt), satPt(pt) ); }
QColorPicker::QColorPicker(QWidget* parent, const char* name )
: QFrame( parent, name )
{
hue = 0; sat = 0;
setCol( 150, 255 );
QImage img( pWidth, pHeight, 32 );
int x,y;
for ( y = 0; y < pHeight; y++ )
for ( x = 0; x < pWidth; x++ ) {
QPoint p( x, y );
img.setPixel( x, y, QColor(huePt(p), satPt(p),
200, QColor::Hsv).rgb() );
}
pix = new QPixmap;
pix->convertFromImage(img);
setBackgroundMode( NoBackground );
}
QColorPicker::~QColorPicker()
{
delete pix;
}
QSize QColorPicker::sizeHint() const
{
return QSize( pWidth + 2*frameWidth(), pHeight + 2*frameWidth() );
}
QSizePolicy QColorPicker::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Fixed );
}
void QColorPicker::setCol( int h, int s )
{
int nhue = QMIN( QMAX(0,h), 360 );
int nsat = QMIN( QMAX(0,s), 255);
if ( nhue == hue && nsat == sat )
return;
QRect r( colPt(), QSize(20,20) );
hue = nhue; sat = nsat;
r = r.unite( QRect( colPt(), QSize(20,20) ) );
r.moveBy( contentsRect().x()-9, contentsRect().y()-9 );
// update( r );
repaint( r, FALSE );
}
void QColorPicker::mouseMoveEvent( QMouseEvent *m )
{
QPoint p = m->pos() - contentsRect().topLeft();
setCol( p );
emit newCol( hue, sat );
}
void QColorPicker::mousePressEvent( QMouseEvent *m )
{
QPoint p = m->pos() - contentsRect().topLeft();
setCol( p );
emit newCol( hue, sat );
}
void QColorPicker::drawContents(QPainter* p)
{
QRect r = contentsRect();
p->drawPixmap( r.topLeft(), *pix );
QPoint pt = colPt() + r.topLeft();
p->setPen( QPen(black) );
p->fillRect( pt.x()-9, pt.y(), 20, 2, black );
p->fillRect( pt.x(), pt.y()-9, 2, 20, black );
}
class QColorShowLabel;
class QColIntValidator: public QIntValidator
{
public:
QColIntValidator( int bottom, int top,
QWidget * parent, const char *name = 0 )
:QIntValidator( bottom, top, parent, name ) {}
QValidator::State validate( QString &, int & ) const;
};
QValidator::State QColIntValidator::validate( QString &s, int &pos ) const
{
State state = QIntValidator::validate(s,pos);
if ( state == Valid ) {
long int val = s.toLong();
// This is not a general solution, assumes that top() > 0 and
// bottom >= 0
if ( val < 0 ) {
s = "0";
pos = 1;
} else if ( val > top() ) {
s.setNum( top() );
pos = s.length();
}
}
return state;
}
class QColNumLineEdit : public QLineEdit
{
public:
QColNumLineEdit( QWidget *parent, const char* name = 0 )
: QLineEdit( parent, name ) { setMaxLength( 3 );}
QSize sizeHint() const {
return QSize( 30, //#####
QLineEdit::sizeHint().height() ); }
void setNum( int i ) {
QString s;
s.setNum(i);
bool block = signalsBlocked();
blockSignals(TRUE);
setText( s );
blockSignals(block);
}
int val() const { return text().toInt(); }
};
class QColorShower : public QWidget
{
Q_OBJECT
public:
QColorShower( QWidget *parent, const char *name = 0 );
//things that don't emit signals
void setHsv( int h, int s, int v );
int currentAlpha() const { return alphaEd->val(); }
void setCurrentAlpha( int a ) { alphaEd->setNum( a ); }
void showAlpha( bool b );
QRgb currentColor() const { return curCol; }
public slots:
void setRgb( QRgb rgb );
signals:
void newCol( QRgb rgb );
private slots:
void rgbEd();
void hsvEd();
private:
void showCurrentColor();
int hue, sat, val;
QRgb curCol;
QColNumLineEdit *hEd;
QColNumLineEdit *sEd;
QColNumLineEdit *vEd;
QColNumLineEdit *rEd;
QColNumLineEdit *gEd;
QColNumLineEdit *bEd;
QColNumLineEdit *alphaEd;
QLabel *alphaLab;
QColorShowLabel *lab;
bool rgbOriginal;
};
class QColorShowLabel : public QFrame
{
Q_OBJECT
public:
QColorShowLabel( QWidget *parent ) :QFrame( parent ) {
setFrameStyle( QFrame::Panel|QFrame::Sunken );
setBackgroundMode( PaletteBackground );
setAcceptDrops( TRUE );
mousePressed = FALSE;
}
void setColor( QColor c ) { col = c; }
signals:
void colorDropped( QRgb );
protected:
void drawContents( QPainter *p );
void mousePressEvent( QMouseEvent *e );
void mouseMoveEvent( QMouseEvent *e );
void mouseReleaseEvent( QMouseEvent *e );
#ifndef QT_NO_DRAGANDDROP
void dragEnterEvent( QDragEnterEvent *e );
void dragLeaveEvent( QDragLeaveEvent *e );
void dropEvent( QDropEvent *e );
#endif
private:
QColor col;
bool mousePressed;
QPoint pressPos;
};
void QColorShowLabel::drawContents( QPainter *p )
{
p->fillRect( contentsRect(), col );
}
void QColorShower::showAlpha( bool b )
{
if ( b ) {
alphaLab->show();
alphaEd->show();
} else {
alphaLab->hide();
alphaEd->hide();
}
}
void QColorShowLabel::mousePressEvent( QMouseEvent *e )
{
mousePressed = TRUE;
pressPos = e->pos();
}
void QColorShowLabel::mouseMoveEvent( QMouseEvent *e )
{
#ifndef QT_NO_DRAGANDDROP
if ( !mousePressed )
return;
if ( ( pressPos - e->pos() ).manhattanLength() > QApplication::startDragDistance() ) {
QColorDrag *drg = new QColorDrag( col, this );
QPixmap pix( 30, 20 );
pix.fill( col );
QPainter p( &pix );
p.drawRect( 0, 0, pix.width(), pix.height() );
p.end();
drg->setPixmap( pix );
mousePressed = FALSE;
drg->dragCopy();
}
#endif
}
#ifndef QT_NO_DRAGANDDROP
void QColorShowLabel::dragEnterEvent( QDragEnterEvent *e )
{
if ( QColorDrag::canDecode( e ) )
e->accept();
else
e->ignore();
}
void QColorShowLabel::dragLeaveEvent( QDragLeaveEvent * )
{
}
void QColorShowLabel::dropEvent( QDropEvent *e )
{
if ( QColorDrag::canDecode( e ) ) {
QColorDrag::decode( e, col );
repaint( FALSE );
emit colorDropped( col.rgb() );
e->accept();
} else {
e->ignore();
}
}
#endif // QT_NO_DRAGANDDROP
void QColorShowLabel::mouseReleaseEvent( QMouseEvent * )
{
if ( !mousePressed )
return;
mousePressed = FALSE;
}
QColorShower::QColorShower( QWidget *parent, const char *name )
:QWidget( parent, name)
{
curCol = qRgb( -1, -1, -1 );
QColIntValidator *val256 = new QColIntValidator( 0, 255, this );
QColIntValidator *val360 = new QColIntValidator( 0, 360, this );
QGridLayout *gl = new QGridLayout( this, 1, 1, 6 );
lab = new QColorShowLabel( this );
lab->setMinimumWidth( 60 ); //###
gl->addMultiCellWidget(lab, 0,-1,0,0);
connect( lab, SIGNAL( colorDropped(QRgb) ),
this, SIGNAL( newCol(QRgb) ) );
connect( lab, SIGNAL( colorDropped(QRgb) ),
this, SLOT( setRgb(QRgb) ) );
hEd = new QColNumLineEdit( this );
hEd->setValidator( val360 );
QLabel *l = new QLabel( hEd, QColorDialog::tr("Hu&e:"), this );
l->setAlignment( AlignRight|AlignVCenter );
gl->addWidget( l, 0, 1 );
gl->addWidget( hEd, 0, 2 );
sEd = new QColNumLineEdit( this );
sEd->setValidator( val256 );
l = new QLabel( sEd, QColorDialog::tr("&Sat:"), this );
l->setAlignment( AlignRight|AlignVCenter );
gl->addWidget( l, 1, 1 );
gl->addWidget( sEd, 1, 2 );
vEd = new QColNumLineEdit( this );
vEd->setValidator( val256 );
l = new QLabel( vEd, QColorDialog::tr("&Val:"), this );
l->setAlignment( AlignRight|AlignVCenter );
gl->addWidget( l, 2, 1 );
gl->addWidget( vEd, 2, 2 );
rEd = new QColNumLineEdit( this );
rEd->setValidator( val256 );
l = new QLabel( rEd, QColorDialog::tr("&Red:"), this );
l->setAlignment( AlignRight|AlignVCenter );
gl->addWidget( l, 0, 3 );
gl->addWidget( rEd, 0, 4 );
gEd = new QColNumLineEdit( this );
gEd->setValidator( val256 );
l = new QLabel( gEd, QColorDialog::tr("&Green:"), this );
l->setAlignment( AlignRight|AlignVCenter );
gl->addWidget( l, 1, 3 );
gl->addWidget( gEd, 1, 4 );
bEd = new QColNumLineEdit( this );
bEd->setValidator( val256 );
l = new QLabel( bEd, QColorDialog::tr("Bl&ue:"), this );
l->setAlignment( AlignRight|AlignVCenter );
gl->addWidget( l, 2, 3 );
gl->addWidget( bEd, 2, 4 );
alphaEd = new QColNumLineEdit( this );
alphaEd->setValidator( val256 );
alphaLab = new QLabel( alphaEd, QColorDialog::tr("A&lpha channel:"), this );
alphaLab->setAlignment( AlignRight|AlignVCenter );
gl->addMultiCellWidget( alphaLab, 3, 3, 1, 3 );
gl->addWidget( alphaEd, 3, 4 );
alphaEd->hide();
alphaLab->hide();
connect( hEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
connect( sEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
connect( vEd, SIGNAL(textChanged(const QString&)), this, SLOT(hsvEd()) );
connect( rEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
connect( gEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
connect( bEd, SIGNAL(textChanged(const QString&)), this, SLOT(rgbEd()) );
}
void QColorShower::showCurrentColor()
{
lab->setColor( currentColor() );
lab->repaint(FALSE); //###
}
void QColorShower::rgbEd()
{
rgbOriginal = TRUE;
curCol = qRgb( rEd->val(), gEd->val(), bEd->val() );
rgb2hsv(currentColor(), hue, sat, val );
hEd->setNum( hue );
sEd->setNum( sat );
vEd->setNum( val );
showCurrentColor();
emit newCol( currentColor() );
}
void QColorShower::hsvEd()
{
rgbOriginal = FALSE;
hue = hEd->val();
sat = sEd->val();
val = vEd->val();
curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
rEd->setNum( qRed(currentColor()) );
gEd->setNum( qGreen(currentColor()) );
bEd->setNum( qBlue(currentColor()) );
showCurrentColor();
emit newCol( currentColor() );
}
void QColorShower::setRgb( QRgb rgb )
{
rgbOriginal = TRUE;
curCol = rgb;
rgb2hsv( currentColor(), hue, sat, val );
hEd->setNum( hue );
sEd->setNum( sat );
vEd->setNum( val );
rEd->setNum( qRed(currentColor()) );
gEd->setNum( qGreen(currentColor()) );
bEd->setNum( qBlue(currentColor()) );
showCurrentColor();
}
void QColorShower::setHsv( int h, int s, int v )
{
rgbOriginal = FALSE;
hue = h; val = v; sat = s; //Range check###
curCol = QColor( hue, sat, val, QColor::Hsv ).rgb();
hEd->setNum( hue );
sEd->setNum( sat );
vEd->setNum( val );
rEd->setNum( qRed(currentColor()) );
gEd->setNum( qGreen(currentColor()) );
bEd->setNum( qBlue(currentColor()) );
showCurrentColor();
}
class QColorDialogPrivate : public QObject
{
Q_OBJECT
public:
QColorDialogPrivate( QColorDialog *p );
QRgb currentColor() const { return cs->currentColor(); }
void setCurrentColor( QRgb rgb );
int currentAlpha() const { return cs->currentAlpha(); }
void setCurrentAlpha( int a ) { cs->setCurrentAlpha( a ); }
void showAlpha( bool b ) { cs->showAlpha( b ); }
private slots:
void addCustom();
void newHsv( int h, int s, int v );
void newColorTypedIn( QRgb rgb );
void newCustom( int, int );
void newStandard( int, int );
private:
QColorPicker *cp;
QColorLuminancePicker *lp;
QWellArray *custom;
QWellArray *standard;
QColorShower *cs;
int nextCust;
bool compact;
};
//sets all widgets to display h,s,v
void QColorDialogPrivate::newHsv( int h, int s, int v )
{
cs->setHsv( h, s, v );
cp->setCol( h, s );
lp->setCol( h, s, v );
}
//sets all widgets to display rgb
void QColorDialogPrivate::setCurrentColor( QRgb rgb )
{
cs->setRgb( rgb );
newColorTypedIn( rgb );
}
//sets all widgets exept cs to display rgb
void QColorDialogPrivate::newColorTypedIn( QRgb rgb )
{
int h, s, v;
rgb2hsv(rgb, h, s, v );
cp->setCol( h, s );
lp->setCol( h, s, v);
}
void QColorDialogPrivate::newCustom( int r, int c )
{
int i = r+2*c;
setCurrentColor( cusrgb[i] );
nextCust = i;
standard->setSelected(-1,-1);
}
void QColorDialogPrivate::newStandard( int r, int c )
{
setCurrentColor( stdrgb[r+c*6] );
custom->setSelected(-1,-1);
}
QColorDialogPrivate::QColorDialogPrivate( QColorDialog *dialog ) :
QObject(dialog)
{
compact = FALSE;
// small displays (e.g. PDAs cannot fit the full color dialog,
// so just use the color picker.
if ( qApp->desktop()->width() < 480 || qApp->desktop()->height() < 350 )
compact = TRUE;
nextCust = 0;
const int lumSpace = 3;
int border = 12;
if ( compact )
border = 6;
QHBoxLayout *topLay = new QHBoxLayout( dialog, border, 6 );
QVBoxLayout *leftLay = 0;
if ( !compact )
leftLay = new QVBoxLayout( topLay );
initRGB();
if ( !compact ) {
standard = new QColorWell( dialog, 6, 8, stdrgb );
standard->setCellSize( 28, 24 );
QLabel * lab = new QLabel( standard,
QColorDialog::tr( "&Basic colors"), dialog );
connect( standard, SIGNAL(selected(int,int)), SLOT(newStandard(int,int)));
leftLay->addWidget( lab );
leftLay->addWidget( standard );
leftLay->addStretch();
custom = new QColorWell( dialog, 2, 8, cusrgb );
custom->setCellSize( 28, 24 );
custom->setAcceptDrops( TRUE );
connect( custom, SIGNAL(selected(int,int)), SLOT(newCustom(int,int)));
lab = new QLabel( custom, QColorDialog::tr( "&Custom colors") , dialog );
leftLay->addWidget( lab );
leftLay->addWidget( custom );
QPushButton *custbut =
new QPushButton( QColorDialog::tr("&Define Custom Colors >>"),
dialog );
custbut->setEnabled( FALSE );
leftLay->addWidget( custbut );
} else {
// better color picker size for small displays
pWidth = 150;
pHeight = 100;
}
QVBoxLayout *rightLay = new QVBoxLayout( topLay );
QHBoxLayout *pickLay = new QHBoxLayout( rightLay );
QVBoxLayout *cLay = new QVBoxLayout( pickLay );
cp = new QColorPicker( dialog );
cp->setFrameStyle( QFrame::Panel + QFrame::Sunken );
cLay->addSpacing( lumSpace );
cLay->addWidget( cp );
cLay->addSpacing( lumSpace );
lp = new QColorLuminancePicker( dialog );
lp->setFixedWidth( 20 ); //###
pickLay->addWidget( lp );
connect( cp, SIGNAL(newCol(int,int)), lp, SLOT(setCol(int,int)) );
connect( lp, SIGNAL(newHsv(int,int,int)), this, SLOT(newHsv(int,int,int)) );
rightLay->addStretch();
cs = new QColorShower( dialog );
connect( cs, SIGNAL(newCol(QRgb)), this, SLOT(newColorTypedIn(QRgb)));
rightLay->addWidget( cs );
QHBoxLayout *buttons;
if ( compact )
buttons = new QHBoxLayout( rightLay );
else
buttons = new QHBoxLayout( leftLay );
QPushButton *ok, *cancel;
ok = new QPushButton( QColorDialog::tr("OK"), dialog );
connect( ok, SIGNAL(clicked()), dialog, SLOT(accept()) );
ok->setDefault(TRUE);
cancel = new QPushButton( QColorDialog::tr("Cancel"), dialog );
connect( cancel, SIGNAL(clicked()), dialog, SLOT(reject()) );
buttons->addWidget( ok );
buttons->addWidget( cancel );
buttons->addStretch();
if ( !compact ) {
QPushButton *addCusBt = new QPushButton(
QColorDialog::tr("&Add To Custom Colors"),
dialog );
rightLay->addWidget( addCusBt );
connect( addCusBt, SIGNAL(clicked()), this, SLOT(addCustom()) );
}
}
void QColorDialogPrivate::addCustom()
{
cusrgb[nextCust] = cs->currentColor();
custom->repaint( FALSE ); //###
nextCust = (nextCust+1) % 16;
}
// BEING REVISED: jo
/*!
\class QColorDialog qcolordialog.h
\brief The QColorDialog class provides a dialog widget for specifying colors.
\ingroup dialogs
The color dialog's function is to allow users to choose colors -
for instance, you might use this in a drawing program to allow the
user to set the brush color.
This version of Qt only provides modal color dialogs. The static
getColor() function shows the dialog and allows the user to specify a color,
while getRgba() does the same but allows the user to specify a color with an
alpha channel (transparency) value.
The user can store customCount() different custom colors. The custom
colors are shared by all color dialogs, and remembered during the
execution of the program. Use setCustomColor() to set the
custom colors, and customColor() to get them.
<img src=qcolordlg-m.png> <img src=qcolordlg-w.png>
*/
/*!
Constructs a default color dialog. Use setColor() for setting an initial value.
\sa getColor()
*/
QColorDialog::QColorDialog(QWidget* parent, const char* name, bool modal) :
QDialog(parent, name, modal )
{
setSizeGripEnabled( TRUE );
d = new QColorDialogPrivate( this );
}
/*!
Pops up a modal color dialog letting the user choose a color and returns
that color. The color is initially set to \a initial. Returns an \link QColor::isValid() invalid\endlink color if the user cancels
the dialog. All colors allocated by the dialog will be deallocated
before this function returns.
*/
QColor QColorDialog::getColor( QColor initial, QWidget *parent,
const char *name )
{
int allocContext = QColor::enterAllocContext();
QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
if ( parent && parent->icon() && !parent->icon()->isNull() )
dlg->setIcon( *parent->icon() );
else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
dlg->setIcon( *qApp->mainWidget()->icon() );
dlg->setCaption( QColorDialog::tr( "Select color" ) );
dlg->setColor( initial );
int resultCode = dlg->exec();
QColor::leaveAllocContext();
QColor result;
if ( resultCode == QDialog::Accepted )
result = dlg->color();
QColor::destroyAllocContext(allocContext);
delete dlg;
return result;
}
/*!
Pops up a modal color dialog, letting the user choose a color and an
alpha channel value. The color+alpha is initially set to \a initial.
If \a ok is non-null, \c *ok is set to TRUE if the user clicked OK,
and FALSE if the user clicked Cancel.
If the user clicks Cancel the \a initial value is returned.
*/
QRgb QColorDialog::getRgba( QRgb initial, bool *ok,
QWidget *parent, const char* name )
{
int allocContext = QColor::enterAllocContext();
QColorDialog *dlg = new QColorDialog( parent, name, TRUE ); //modal
dlg->setColor( initial );
dlg->setSelectedAlpha( qAlpha(initial) );
int resultCode = dlg->exec();
QColor::leaveAllocContext();
QRgb result = initial;
if ( resultCode == QDialog::Accepted ) {
QRgb c = dlg->color().rgb();
int alpha = dlg->selectedAlpha();
result = qRgba( qRed(c), qGreen(c), qBlue(c), alpha );
}
if ( ok )
*ok = resultCode == QDialog::Accepted;
QColor::destroyAllocContext(allocContext);
delete dlg;
return result;
}
/*!
Returns the color currently selected in the dialog.
\sa setColor()
*/
QColor QColorDialog::color() const
{
return QColor(d->currentColor());
}
/*! Destructs the dialog and frees any memory it allocated.
*/
diff --git a/libqtaux/qinputdialog.cpp b/libqtaux/qinputdialog.cpp
index 821c74d..43e243f 100644
--- a/libqtaux/qinputdialog.cpp
+++ b/libqtaux/qinputdialog.cpp
@@ -1,493 +1,492 @@
/****************************************************************************
** $Id$
**
** Implementation of QInputDialog class
**
** Created : 991212
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of the dialogs module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "qinputdialog.h"
#include <qlayout.h>
#include <qlabel.h>
-#include <qlineedit.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qcombobox.h>
#include <qwidgetstack.h>
#include <qvalidator.h>
#include <qapplication.h>
class QInputDialogPrivate
{
public:
friend class QInputDialog;
QLineEdit *lineEdit;
QSpinBox *spinBox;
QComboBox *comboBox, *editComboBox;
QPushButton *ok;
QWidgetStack *stack;
QInputDialog::Type type;
};
/*!
\class QInputDialog qinputdialog.h
\brief A convenience dialog to get a simple input from the user
\ingroup dialogs
The QInputDialog is a simple dialog which can be used if you
need a simple input from the user. This can be text, a number or
an item from a list. Also a label has to be set to tell the user
what he/she should input.
In this Qt version only the 4 static convenience functions
getText(), getInteger(), getDouble() and getItem() of QInputDialog
are available.
Use it like this:
\code
bool ok = FALSE;
QString text = QInputDialog::getText( tr( "Make an input" ), tr( "Please enter your name" ), QString::null, &ok, this );
if ( ok && !text.isEmpty() )
;// user entered something and pressed ok
else
;// user entered nothing or pressed cancel
\endcode
There are more static convenience methods!
\sa getText(), getInteger(), getDouble(), getItem()
*/
/*!
\enum QInputDialog::Type
This enum type specifies the type of the dialog
(which kind of input can be done):
<ul>
<li>\c LineEdit - A QLineEdit is used for taking the input, so a textual or
(e.g. using a QValidator) a numerical input can be done. Using lineEdit()
the QLineEdit can be accessed.
<li>\c SpinBox - A QSpinBox is used for taking the input, so a decimal
input can be done. Using spinBox() the QSpinBox can be accessed.
<li>\c ComboBox - A read-only QComboBox is used for taking the input,
so one item of a list can be chosen. Using comboBox() the QComboBox
can be accessed.
<li>\c EditableComboBox - An editable QComboBox is used for taking the input,
so either one item of a list can be chosen or a text can be entered. Using
editableComboBox() the QComboBox can be accessed.
</ul>
*/
/*!
Constructs the dialog. \a label is the text which is shown to the user (it should mention
to the user what he/she should input), \a parent the parent widget of the dialog, \a name
the name of it and if you set \a modal to TRUE, the dialog pops up modally, else it pops
up modeless. With \a type you specify the type of the dialog.
\sa getText(), getInteger(), getDouble(), getItem()
*/
QInputDialog::QInputDialog( const QString &label, QWidget* parent, const char* name,
bool modal, Type type)
: QDialog( parent, name, modal )
{
if ( parent && parent->icon() &&!parent->icon()->isNull() )
setIcon( *parent->icon() );
else if ( qApp->mainWidget() && qApp->mainWidget()->icon() && !qApp->mainWidget()->icon()->isNull() )
QDialog::setIcon( *qApp->mainWidget()->icon() );
d = new QInputDialogPrivate;
d->lineEdit = 0;
d->spinBox = 0;
d->comboBox = 0;
QVBoxLayout *vbox = new QVBoxLayout( this, 6, 6 );
QLabel* l = new QLabel( label, this );
vbox->addWidget( l );
d->stack = new QWidgetStack( this );
vbox->addWidget( d->stack );
d->lineEdit = new QLineEdit( d->stack );
d->spinBox = new QSpinBox( d->stack );
d->comboBox = new QComboBox( FALSE, d->stack );
d->editComboBox = new QComboBox( TRUE, d->stack );
QHBoxLayout *hbox = new QHBoxLayout( 6 );
vbox->addLayout( hbox, AlignRight );
d->ok = new QPushButton( tr( "&OK" ), this );
d->ok->setDefault( TRUE );
QPushButton *cancel = new QPushButton( tr( "&Cancel" ), this );
QSize bs( d->ok->sizeHint() );
if ( cancel->sizeHint().width() > bs.width() )
bs.setWidth( cancel->sizeHint().width() );
d->ok->setFixedSize( bs );
cancel->setFixedSize( bs );
hbox->addWidget( new QWidget( this ) );
hbox->addWidget( d->ok );
hbox->addWidget( cancel );
connect( d->lineEdit, SIGNAL( returnPressed() ),
this, SLOT( tryAccept() ) );
connect( d->lineEdit, SIGNAL( textChanged(const QString&) ),
this, SLOT( textChanged(const QString&) ) );
connect( d->ok, SIGNAL( clicked() ), this, SLOT( accept() ) );
connect( cancel, SIGNAL( clicked() ), this, SLOT( reject() ) );
resize( QMAX( sizeHint().width(), 400 ), sizeHint().height() );
setType( type );
}
/*!
Returns the line edit, which is used in the LineEdit mode
*/
QLineEdit *QInputDialog::lineEdit() const
{
return d->lineEdit;
}
/*!
Returns the spinbox, which is used in the SpinBox mode
*/
QSpinBox *QInputDialog::spinBox() const
{
return d->spinBox;
}
/*!
Returns the combobox, which is used in the ComboBox mode
*/
QComboBox *QInputDialog::comboBox() const
{
return d->comboBox;
}
/*!
Returns the combobox, which is used in the EditableComboBox mode
*/
QComboBox *QInputDialog::editableComboBox() const
{
return d->editComboBox;
}
/*!
Sets the input type of the dialog to \a t.
*/
void QInputDialog::setType( Type t )
{
switch ( t ) {
case LineEdit:
d->stack->raiseWidget( d->lineEdit );
d->lineEdit->setFocus();
break;
case SpinBox:
d->stack->raiseWidget( d->spinBox );
d->spinBox->setFocus();
break;
case ComboBox:
d->stack->raiseWidget( d->comboBox );
d->comboBox->setFocus();
break;
case EditableComboBox:
d->stack->raiseWidget( d->editComboBox );
d->editComboBox->setFocus();
break;
}
d->type = t;
}
/*!
Returns the input type of the dialog.
\sa setType()
*/
QInputDialog::Type QInputDialog::type() const
{
return d->type;
}
/*!
Destructor.
*/
QInputDialog::~QInputDialog()
{
delete d;
}
/*!
Static convenience function to get a textual input from the user. \a caption is the text
which is displayed in the title bar of the dialog. \a label is the text which
is shown to the user (it should mention to the user what he/she should input), \a text
the default text which will be initially set to the line edit, \a ok a pointer to
a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
user pressed cancel, \a parent the parent widget of the dialog and \a name
the name of it. The dialogs pops up modally!
This method returns the text which has been entered in the line edit.
You will use this static method like this:
\code
bool ok = FALSE;
QString text = QInputDialog::getText( tr( "Please enter your name" ), QString::null, &ok, this );
if ( ok && !text.isEmpty() )
;// user entered something and pressed ok
else
;// user entered nothing or pressed cancel
\endcode
*/
QString QInputDialog::getText( const QString &caption, const QString &label, const QString &text,
bool *ok, QWidget *parent, const char *name )
{
return getText( caption, label, QLineEdit::Normal, text, ok, parent, name );
}
/*!
Like above, but accepts an a \a mode which the line edit will use to display text.
\sa getText()
*/
QString QInputDialog::getText( const QString &caption, const QString &label, QLineEdit::EchoMode mode,
const QString &text, bool *ok, QWidget *parent, const char *name )
{
QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit );
dlg->setCaption( caption );
dlg->lineEdit()->setText( text );
dlg->lineEdit()->setEchoMode( mode );
if ( !text.isEmpty() )
dlg->lineEdit()->selectAll();
bool ok_ = FALSE;
QString result;
ok_ = dlg->exec() == QDialog::Accepted;
if ( ok )
*ok = ok_;
if ( ok_ )
result = dlg->lineEdit()->text();
delete dlg;
return result;
}
/*!
Static convenience function to get an integral input from the user. \a caption is the text
which is displayed in the title bar of the dialog. \a label is the text which
is shown to the user (it should mention to the user what he/she should input), \a num
the default number which will be initially set to the spinbox, \a from and \a to the
range in which the entered number has to be, \a step the step in which the number can
be increased/decreased by the spinbox, \a ok a pointer to
a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
user pressed cancel, \a parent the parent widget of the dialog and \a name
the name of it. The dialogs pops up modally!
This method returns the number which has been entered by the user.
You will use this static method like this:
\code
bool ok = FALSE;
int res = QInputDialog::getInteger( tr( "Please enter a number" ), 22, 0, 1000, 2, &ok, this );
if ( ok )
;// user entered something and pressed ok
else
;// user pressed cancel
\endcode
*/
int QInputDialog::getInteger( const QString &caption, const QString &label, int num, int from, int to, int step,
bool *ok, QWidget *parent, const char *name )
{
QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, SpinBox );
dlg->setCaption( caption );
dlg->spinBox()->setRange( from, to );
dlg->spinBox()->setSteps( step, 0 );
dlg->spinBox()->setValue( num );
bool ok_ = FALSE;
int result;
ok_ = dlg->exec() == QDialog::Accepted;
if ( ok )
*ok = ok_;
result = dlg->spinBox()->value();
delete dlg;
return result;
}
/*!
Static convenience function to get a decimal input from the user. \a caption is the text
which is displayed in the title bar of the dialog. \a label is the text which
is shown to the user (it should mention to the user what he/she should input), \a num
the default decimal number which will be initially set to the line edit, \a from and \a to the
range in which the entered number has to be, \a decimals the number of decimal which
the number may have, \a ok a pointer to
a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
user pressed cancel, \a parent the parent widget of the dialog and \a name
the name of it. The dialogs pops up modally!
This method returns the number which has been entered by the user.
You will use this static method like this:
\code
bool ok = FALSE;
double res = QInputDialog::getDouble( tr( "Please enter a decimal number" ), 33.7, 0, 1000, 2, &ok, this );
if ( ok )
;// user entered something and pressed ok
else
;// user pressed cancel
\endcode
*/
double QInputDialog::getDouble( const QString &caption, const QString &label, double num,
double from, double to, int decimals,
bool *ok, QWidget *parent, const char *name )
{
QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, LineEdit );
dlg->setCaption( caption );
dlg->lineEdit()->setValidator( new QDoubleValidator( from, to, decimals, dlg->lineEdit() ) );
dlg->lineEdit()->setText( QString::number( num, 'f', decimals ) );
dlg->lineEdit()->selectAll();
bool accepted = ( dlg->exec() == QDialog::Accepted );
if ( ok )
*ok = accepted;
double result = dlg->lineEdit()->text().toDouble();
delete dlg;
return result;
}
/*!
Static convenience function to let the user select an item from a string list. \a caption is the text
which is displayed in the title bar of the dialog. \a label is the text which
is shown to the user (it should mention to the user what he/she should input), \a list the
string list which is inserted into the combobox, \a current the number of the item which should
be initially the current item, \a editable specifies if the combobox should be editable (if it is TRUE)
or read-only (if \a editable is FALSE), \a ok a pointer to
a bool which will be (if not 0!) set to TRUE if the user pressed ok or to FALSE if the
user pressed cancel, \a parent the parent widget of the dialog and \a name
the name of it. The dialogs pops up modally!
This method returns the text of the current item, or if \a editable was TRUE, the current
text of the combobox.
You will use this static method like this:
\code
QStringList lst;
lst << "First" << "Second" << "Third" << "Fourth" << "Fifth";
bool ok = FALSE;
QString res = QInputDialog::getItem( tr( "Please select an item" ), lst, 1, TRUE, &ok, this );
if ( ok )
;// user selected an item and pressed ok
else
;// user pressed cancel
\endcode
*/
QString QInputDialog::getItem( const QString &caption, const QString &label, const QStringList &list,
int current, bool editable,
bool *ok, QWidget *parent, const char *name )
{
QInputDialog *dlg = new QInputDialog( label, parent, name, TRUE, editable ? EditableComboBox : ComboBox );
dlg->setCaption( caption );
if ( editable ) {
dlg->editableComboBox()->insertStringList( list );
dlg->editableComboBox()->setCurrentItem( current );
} else {
dlg->comboBox()->insertStringList( list );
dlg->comboBox()->setCurrentItem( current );
}
bool ok_ = FALSE;
QString result;
ok_ = dlg->exec() == QDialog::Accepted;
if ( ok )
*ok = ok_;
if ( editable )
result = dlg->editableComboBox()->currentText();
else
result = dlg->comboBox()->currentText();
delete dlg;
return result;
}
/*!
\internal
*/
void QInputDialog::textChanged( const QString &s )
{
bool on;
if ( d->lineEdit->validator() ) {
QString str = d->lineEdit->text();
int index = d->lineEdit->cursorPosition();
on = ( d->lineEdit->validator()->validate(str, index) ==
QValidator::Acceptable );
} else {
on = !s.isEmpty();
}
d->ok->setEnabled( on );
}
/*!
\internal
*/
void QInputDialog::tryAccept()
{
if ( !d->lineEdit->text().isEmpty() )
accept();
}
diff --git a/libqtaux/qsplitter.cpp b/libqtaux/qsplitter.cpp
index ab6e01b..39321f8 100644
--- a/libqtaux/qsplitter.cpp
+++ b/libqtaux/qsplitter.cpp
@@ -1,1128 +1,1124 @@
/****************************************************************************
** $Id$
**
** Splitter widget
**
** Created: 980105
**
** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
**
** This file is part of the widgets module of the Qt GUI Toolkit.
**
** This file may be distributed under the terms of the Q Public License
** as defined by Trolltech AS of Norway and appearing in the file
** LICENSE.QPL included in the packaging of this file.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
** licenses may use this file in accordance with the Qt Commercial License
** Agreement provided with the Software.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
** information about Qt Commercial License Agreements.
** See http://www.trolltech.com/qpl/ for QPL licensing information.
** See http://www.trolltech.com/gpl/ for GPL licensing information.
**
** Contact info@trolltech.com if any conditions of this licensing are
** not clear to you.
**
**********************************************************************/
#include "qsplitter.h"
-#include "qpainter.h"
#include "qdrawutil.h"
-#include "qbitmap.h"
#include "qlayoutengine_p.h"
-#include "qlist.h"
-#include "qarray.h"
#include "qobjectlist.h"
#include "qapplication.h" //sendPostedEvents
class QSplitterHandle : public QWidget
{
public:
QSplitterHandle( Qt::Orientation o,
QSplitter *parent, const char* name=0 );
void setOrientation( Qt::Orientation o );
Qt::Orientation orientation() const { return orient; }
bool opaque() const { return s->opaqueResize(); }
QSize sizeHint() const;
QSizePolicy sizePolicy() const;
int id() const { return myId; } // data->list.at(id())->wid == this
void setId( int i ) { myId = i; }
protected:
void paintEvent( QPaintEvent * );
void mouseMoveEvent( QMouseEvent * );
void mousePressEvent( QMouseEvent * );
void mouseReleaseEvent( QMouseEvent * );
private:
Qt::Orientation orient;
bool opaq;
int myId;
QSplitter *s;
};
static int mouseOffset;
static int opaqueOldPos = -1; //### there's only one mouse, but this is a bit risky
QSplitterHandle::QSplitterHandle( Qt::Orientation o,
QSplitter *parent, const char * name )
: QWidget( parent, name )
{
s = parent;
setOrientation(o);
}
QSizePolicy QSplitterHandle::sizePolicy() const
{
//### removeme 3.0
return QWidget::sizePolicy();
}
QSize QSplitterHandle::sizeHint() const
{
int sw = style().splitterWidth();
return QSize(sw,sw).expandedTo( QApplication::globalStrut() );
}
void QSplitterHandle::setOrientation( Qt::Orientation o )
{
orient = o;
#ifndef QT_NO_CURSOR
if ( o == QSplitter::Horizontal )
setCursor( splitHCursor );
else
setCursor( splitVCursor );
#endif
}
void QSplitterHandle::mouseMoveEvent( QMouseEvent *e )
{
if ( !(e->state()&LeftButton) )
return;
QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()))
- mouseOffset;
if ( opaque() ) {
s->moveSplitter( pos, id() );
} else {
int min = pos; int max = pos;
s->getRange( id(), &min, &max );
s->setRubberband( QMAX( min, QMIN(max, pos )));
}
}
void QSplitterHandle::mousePressEvent( QMouseEvent *e )
{
if ( e->button() == LeftButton )
mouseOffset = s->pick(e->pos());
}
void QSplitterHandle::mouseReleaseEvent( QMouseEvent *e )
{
if ( !opaque() && e->button() == LeftButton ) {
QCOORD pos = s->pick(parentWidget()->mapFromGlobal(e->globalPos()));
s->setRubberband( -1 );
s->moveSplitter( pos, id() );
}
}
void QSplitterHandle::paintEvent( QPaintEvent * )
{
QPainter p( this );
s->drawSplitter( &p, 0, 0, width(), height() );
}
class QSplitterLayoutStruct
{
public:
QSplitter::ResizeMode mode;
QCOORD sizer;
bool isSplitter;
QWidget *wid;
};
class QSplitterData
{
public:
QSplitterData() : opaque( FALSE ), firstShow( TRUE ) {}
QList<QSplitterLayoutStruct> list;
bool opaque;
bool firstShow;
};
// NOT REVISED
/*!
\class QSplitter qsplitter.h
\brief The QSplitter class implements a splitter widget.
\ingroup organizers
A splitter lets the user control the size of child widgets by
dragging the boundary between the children. Any number of widgets
may be controlled.
To show a QListBox, a QListView and a QMultiLineEdit side by side:
\code
QSplitter *split = new QSplitter( parent );
QListBox *lb = new QListBox( split );
QListView *lv = new QListView( split );
QMultiLineEdit *ed = new QMultiLineEdit( split );
\endcode
In QSplitter the boundary can be either horizontal or vertical. The
default is horizontal (the children are side by side) and you
can use setOrientation( QSplitter::Vertical ) to set it to vertical.
By default, all widgets can be as large or as small as the user
wishes, down to \link QWidget::minimumSizeHint() minimumSizeHint()\endlink.
You can naturally use setMinimumSize() and/or
setMaximumSize() on the children. Use setResizeMode() to specify that
a widget should keep its size when the splitter is resized.
QSplitter normally resizes the children only at the end of a
resize operation, but if you call setOpaqueResize( TRUE ), the
widgets are resized as often as possible.
The initial distribution of size between the widgets is determined
by the initial size of each widget. You can also use setSizes() to
set the sizes of all the widgets. The function sizes() returns the
sizes set by the user.
If you hide() a child, its space will be distributed among the other
children. When you show() it again, it will be reinstated.
<img src=qsplitter-m.png> <img src=qsplitter-w.png>
\sa QTabBar
*/
static QSize minSize( const QWidget *w )
{
QSize min = w->minimumSize();
QSize s;
if ( min.height() <= 0 || min.width() <= 0 )
s = w->minimumSizeHint();
if ( min.height() > 0 )
s.setHeight( min.height() );
if ( min.width() > 0 )
s.setWidth( min.width() );
return s.expandedTo(QSize(0,0));
}
/*!
Constructs a horizontal splitter.
*/
QSplitter::QSplitter( QWidget *parent, const char *name )
:QFrame(parent,name,WPaintUnclipped)
{
orient = Horizontal;
init();
}
/*!
Constructs splitter with orientation \a o.
*/
QSplitter::QSplitter( Orientation o, QWidget *parent, const char *name )
:QFrame(parent,name,WPaintUnclipped)
{
orient = o;
init();
}
/*!
Destructs the splitter.
*/
QSplitter::~QSplitter()
{
data->list.setAutoDelete( TRUE );
delete data;
}
void QSplitter::init()
{
data = new QSplitterData;
if ( orient == Horizontal )
setSizePolicy( QSizePolicy(QSizePolicy::Fixed,QSizePolicy::Minimum) );
else
setSizePolicy( QSizePolicy(QSizePolicy::Minimum,QSizePolicy::Fixed) );
}
/*!
\fn void QSplitter::refresh()
Updates the splitter state. You should not need to call this
function during normal use of the splitter.
*/
/*! Sets the orientation to \a o. By default the orientation is
horizontal (the widgets are side by side).
\sa orientation()
*/
void QSplitter::setOrientation( Orientation o )
{
if ( orient == o )
return;
orient = o;
if ( orient == Horizontal )
setSizePolicy( QSizePolicy( QSizePolicy::Fixed, QSizePolicy::Minimum ) );
else
setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Fixed ) );
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->isSplitter )
((QSplitterHandle*)s->wid)->setOrientation( o );
s = data->list.next(); // ### next at end of loop, no iterator
}
recalc( isVisible() );
}
/*!
\fn Orientation QSplitter::orientation() const
Returns the orientation (\c Horizontal or \c Vertical) of the splitter.
\sa setOrientation()
*/
/*!
\reimp
*/
void QSplitter::resizeEvent( QResizeEvent * )
{
doResize();
}
/*!
Inserts the widget \a w at the end, or at the beginning if \a first is TRUE
It is the responsibility of the caller of this function to make sure
that \a w is not already in the splitter, and to call recalcId if
needed. (If \a first is TRUE, then recalcId is very probably
needed.)
*/
QSplitterLayoutStruct *QSplitter::addWidget( QWidget *w, bool first )
{
QSplitterLayoutStruct *s;
QSplitterHandle *newHandle = 0;
if ( data->list.count() > 0 ) {
s = new QSplitterLayoutStruct;
s->mode = KeepSize;
newHandle = new QSplitterHandle( orientation(), this );
s->wid = newHandle;
newHandle->setId(data->list.count());
s->isSplitter = TRUE;
s->sizer = pick( newHandle->sizeHint() );
if ( first )
data->list.insert( 0, s );
else
data->list.append( s );
}
s = new QSplitterLayoutStruct;
s->mode = Stretch;
s->wid = w;
if ( !testWState( WState_Resized ) && w->sizeHint().isValid() )
s->sizer = pick( w->sizeHint() );
else
s->sizer = pick( w->size() );
s->isSplitter = FALSE;
if ( first )
data->list.insert( 0, s );
else
data->list.append( s );
if ( newHandle && isVisible() )
newHandle->show(); //will trigger sending of post events
return s;
}
/*!
Tells the splitter that a child widget has been inserted/removed.
*/
void QSplitter::childEvent( QChildEvent *c )
{
if ( c->type() == QEvent::ChildInserted ) {
if ( !c->child()->isWidgetType() )
return;
if ( ((QWidget*)c->child())->testWFlags( WType_TopLevel ) )
return;
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->wid == c->child() )
return;
s = data->list.next();
}
addWidget( (QWidget*)c->child() );
recalc( isVisible() );
} else if ( c->type() == QEvent::ChildRemoved ) {
QSplitterLayoutStruct *p = 0;
if ( data->list.count() > 1 )
p = data->list.at(1); //remove handle _after_ first widget.
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->wid == c->child() ) {
data->list.removeRef( s );
delete s;
if ( p && p->isSplitter ) {
data->list.removeRef( p );
delete p->wid; //will call childEvent
delete p;
}
recalcId();
doResize();
return;
}
p = s;
s = data->list.next();
}
}
}
/*!
Shows a rubber band at position \a p. If \a p is negative, the
rubber band is removed.
*/
void QSplitter::setRubberband( int p )
{
QPainter paint( this );
paint.setPen( gray );
paint.setBrush( gray );
paint.setRasterOp( XorROP );
QRect r = contentsRect();
const int rBord = 3; //Themable????
const int sw = style().splitterWidth();
if ( orient == Horizontal ) {
if ( opaqueOldPos >= 0 )
paint.drawRect( opaqueOldPos + sw/2 - rBord , r.y(),
2*rBord, r.height() );
if ( p >= 0 )
paint.drawRect( p + sw/2 - rBord, r.y(), 2*rBord, r.height() );
} else {
if ( opaqueOldPos >= 0 )
paint.drawRect( r.x(), opaqueOldPos + sw/2 - rBord,
r.width(), 2*rBord );
if ( p >= 0 )
paint.drawRect( r.x(), p + sw/2 - rBord, r.width(), 2*rBord );
}
opaqueOldPos = p;
}
/*! \reimp */
bool QSplitter::event( QEvent *e )
{
if ( e->type() == QEvent::LayoutHint || ( e->type() == QEvent::Show && data->firstShow ) ) {
recalc( isVisible() );
if ( e->type() == QEvent::Show )
data->firstShow = FALSE;
}
return QWidget::event( e );
}
/*!
Draws the splitter handle in the rectangle described by \a x, \a y,
\a w, \a h using painter \a p.
\sa QStyle::drawSplitter
*/
void QSplitter::drawSplitter( QPainter *p,
QCOORD x, QCOORD y, QCOORD w, QCOORD h )
{
style().drawSplitter( p, x, y, w, h, colorGroup(), orient );
}
/*!
Returns the id of the splitter to the right of or below the widget \a w,
or 0 if there is no such splitter.
(ie. it is either not in this QSplitter, or it is at the end).
*/
int QSplitter::idAfter( QWidget* w ) const
{
QSplitterLayoutStruct *s = data->list.first();
bool seen_w = FALSE;
while ( s ) {
if ( s->isSplitter && seen_w )
return data->list.at();
if ( !s->isSplitter && s->wid == w )
seen_w = TRUE;
s = data->list.next();
}
return 0;
}
/*!
Moves the left/top edge of the splitter handle with id \a id as
close as possible to \a p which is the distance from the left (or
top) edge of the widget.
\sa idAfter()
*/
void QSplitter::moveSplitter( QCOORD p, int id )
{
p = adjustPos( p, id );
QSplitterLayoutStruct *s = data->list.at(id);
int oldP = orient == Horizontal? s->wid->x() : s->wid->y();
bool upLeft = p < oldP;
moveAfter( p, id, upLeft );
moveBefore( p-1, id-1, upLeft );
storeSizes();
}
void QSplitter::setG( QWidget *w, int p, int s )
{
if ( orient == Horizontal )
w->setGeometry( p, contentsRect().y(), s, contentsRect().height() );
else
w->setGeometry( contentsRect().x(), p, contentsRect().width(), s );
}
/*!
Places the right/bottom edge of the widget at \a id at position \a pos.
\sa idAfter()
*/
void QSplitter::moveBefore( int pos, int id, bool upLeft )
{
QSplitterLayoutStruct *s = data->list.at(id);
if ( !s )
return;
QWidget *w = s->wid;
if ( w->isHidden() ) {
moveBefore( pos, id-1, upLeft );
} else if ( s->isSplitter ) {
int dd = s->sizer;
if ( upLeft ) {
setG( w, pos-dd+1, dd );
moveBefore( pos-dd, id-1, upLeft );
} else {
moveBefore( pos-dd, id-1, upLeft );
setG( w, pos-dd+1, dd );
}
} else {
int left = pick( w->pos() );
int dd = pos - left + 1;
dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
int newLeft = pos-dd+1;
setG( w, newLeft, dd );
if ( left != newLeft )
moveBefore( newLeft-1, id-1, upLeft );
}
}
/*!
Places the left/top edge of the widget at \a id at position \a pos.
\sa idAfter()
*/
void QSplitter::moveAfter( int pos, int id, bool upLeft )
{
QSplitterLayoutStruct *s = id < int(data->list.count()) ?
data->list.at(id) : 0;
if ( !s )
return;
QWidget *w = s->wid;
if ( w->isHidden() ) {
moveAfter( pos, id+1, upLeft );
} else if ( pick( w->pos() ) == pos ) {
//No need to do anything if it's already there.
return;
} else if ( s->isSplitter ) {
int dd = s->sizer;
if ( upLeft ) {
setG( w, pos, dd );
moveAfter( pos+dd, id+1, upLeft );
} else {
moveAfter( pos+dd, id+1, upLeft );
setG( w, pos, dd );
}
} else {
int right = pick( w->geometry().bottomRight() );
int dd = right - pos + 1;
dd = QMAX( pick(minSize(w)), QMIN(dd, pick(w->maximumSize())));
int newRight = pos+dd-1;
setG( w, pos, dd );
moveAfter( newRight+1, id+1, upLeft );
}
}
/*!
Returns the valid range of the splitter with id \a id in \a min and \a max.
\sa idAfter()
*/
void QSplitter::getRange( int id, int *min, int *max )
{
int minB = 0; //before
int maxB = 0;
int minA = 0;
int maxA = 0; //after
int n = data->list.count();
if ( id < 0 || id >= n )
return;
int i;
for ( i = 0; i < id; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
if ( s->wid->isHidden() ) {
//ignore
} else if ( s->isSplitter ) {
minB += s->sizer;
maxB += s->sizer;
} else {
minB += pick( minSize(s->wid) );
maxB += pick( s->wid->maximumSize() );
}
}
for ( i = id; i < n; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
if ( s->wid->isHidden() ) {
//ignore
} else if ( s->isSplitter ) {
minA += s->sizer;
maxA += s->sizer;
} else {
minA += pick( minSize(s->wid) );
maxA += pick( s->wid->maximumSize() );
}
}
QRect r = contentsRect();
if ( min )
*min = pick(r.topLeft()) + QMAX( minB, pick(r.size())-maxA );
if ( max )
*max = pick(r.topLeft()) + QMIN( maxB, pick(r.size())-minA );
}
/*!
Returns the legal position closest to \a p of the splitter with id \a id.
\sa idAfter()
*/
int QSplitter::adjustPos( int p, int id )
{
int min = 0;
int max = 0;
getRange( id, &min, &max );
p = QMAX( min, QMIN( p, max ) );
return p;
}
void QSplitter::doResize()
{
QRect r = contentsRect();
int i;
int n = data->list.count();
QArray<QLayoutStruct> a( n );
for ( i = 0; i< n; i++ ) {
a[i].init();
QSplitterLayoutStruct *s = data->list.at(i);
if ( s->wid->isHidden() ) {
a[i].stretch = 0;
a[i].sizeHint = a[i].minimumSize = 0;
a[i].maximumSize = 0;
} else if ( s->isSplitter ) {
a[i].stretch = 0;
a[i].sizeHint = a[i].minimumSize = a[i].maximumSize = s->sizer;
a[i].empty = FALSE;
} else if ( s->mode == KeepSize ) {
a[i].stretch = 0;
a[i].minimumSize = pick( minSize(s->wid) );
a[i].sizeHint = s->sizer;
a[i].maximumSize = pick( s->wid->maximumSize() );
a[i].empty = FALSE;
} else if ( s->mode == FollowSizeHint ) {
a[i].stretch = 0;
a[i].minimumSize = a[i].sizeHint = pick( s->wid->sizeHint() );
a[i].maximumSize = pick( s->wid->maximumSize() );
a[i].empty = FALSE;
} else { //proportional
a[i].stretch = s->sizer;
a[i].maximumSize = pick( s->wid->maximumSize() );
a[i].sizeHint = a[i].minimumSize = pick( minSize(s->wid) );
a[i].empty = FALSE;
}
}
qGeomCalc( a, 0, n, pick( r.topLeft() ), pick( r.size() ), 0 );
for ( i = 0; i< n; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
if ( orient == Horizontal )
s->wid->setGeometry( a[i].pos, r.top(), a[i].size, r.height() );
else
s->wid->setGeometry( r.left(), a[i].pos, r.width(), a[i].size );
}
}
void QSplitter::recalc( bool update )
{
int fi = 2*frameWidth();
int maxl = fi;
int minl = fi;
int maxt = QWIDGETSIZE_MAX;
int mint = fi;
int n = data->list.count();
bool first = TRUE;
/*
The splitter before a hidden widget is always hidden.
The splitter before the first visible widget is hidden.
The splitter before any other visible widget is visible.
*/
for ( int i = 0; i< n; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
if ( !s->isSplitter ) {
QSplitterLayoutStruct *p = (i > 0) ? p = data->list.at( i-1 ) : 0;
if ( p && p->isSplitter )
if ( first || s->wid->isHidden() )
p->wid->hide(); //may trigger new recalc
else
p->wid->show(); //may trigger new recalc
if ( !s->wid->isHidden() )
first = FALSE;
}
}
bool empty=TRUE;
for ( int j = 0; j< n; j++ ) {
QSplitterLayoutStruct *s = data->list.at(j);
if ( !s->wid->isHidden() ) {
empty = FALSE;
if ( s->isSplitter ) {
minl += s->sizer;
maxl += s->sizer;
} else {
QSize minS = minSize(s->wid);
minl += pick( minS );
maxl += pick( s->wid->maximumSize() );
mint = QMAX( mint, trans( minS ));
int tm = trans( s->wid->maximumSize() );
if ( tm > 0 )
maxt = QMIN( maxt, tm );
}
}
}
if ( empty )
maxl = maxt = 0;
else
maxl = QMIN( maxl, QWIDGETSIZE_MAX );
if ( maxt < mint )
maxt = mint;
if ( orient == Horizontal ) {
setMaximumSize( maxl, maxt );
setMinimumSize( minl, mint );
} else {
setMaximumSize( maxt, maxl );
setMinimumSize( mint, minl );
}
if ( update )
doResize();
}
/*! \enum QSplitter::ResizeMode
This enum type describes how QSplitter will resize each of its child widgets. The currently defined values are: <ul>
<li> \c Stretch - the widget will be resized when the splitter
itself is resized.
<li> \c KeepSize - QSplitter will try to keep this widget's size
unchanged.
<li> \c FollowSizeHint - QSplitter will resize the widget when its
size hint changes.
</ul>
*/
/*!
Sets resize mode of \a w to \a mode.
\sa ResizeMode
*/
void QSplitter::setResizeMode( QWidget *w, ResizeMode mode )
{
processChildEvents();
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->wid == w ) {
s->mode = mode;
return;
}
s = data->list.next();
}
s = addWidget( w, TRUE );
s->mode = mode;
}
/*!
Returns TRUE if opaque resize is on, FALSE otherwise.
\sa setOpaqueResize()
*/
bool QSplitter::opaqueResize() const
{
return data->opaque;
}
/*!
Sets opaque resize to \a on. Opaque resize is initially turned off.
\sa opaqueResize()
*/
void QSplitter::setOpaqueResize( bool on )
{
data->opaque = on;
}
/*!
Moves \a w to the leftmost/top position.
*/
void QSplitter::moveToFirst( QWidget *w )
{
processChildEvents();
bool found = FALSE;
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->wid == w ) {
found = TRUE;
QSplitterLayoutStruct *p = data->list.prev();
if ( p ) { // not already at first place
data->list.take(); //take p
data->list.take(); // take s
data->list.insert( 0, p );
data->list.insert( 0, s );
}
break;
}
s = data->list.next();
}
if ( !found )
addWidget( w, TRUE );
recalcId();
}
/*!
Moves \a w to the rightmost/bottom position.
*/
void QSplitter::moveToLast( QWidget *w )
{
processChildEvents();
bool found = FALSE;
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->wid == w ) {
found = TRUE;
data->list.take(); // take s
QSplitterLayoutStruct *p = data->list.current();
if ( p ) { // the splitter handle after s
data->list.take(); //take p
data->list.append( p );
}
data->list.append( s );
break;
}
s = data->list.next();
}
if ( !found )
addWidget( w);
recalcId();
}
void QSplitter::recalcId()
{
int n = data->list.count();
for ( int i = 0; i < n; i++ ) {
QSplitterLayoutStruct *s = data->list.at(i);
if ( s->isSplitter )
((QSplitterHandle*)s->wid)->setId(i);
}
}
/*!\reimp
*/
QSize QSplitter::sizeHint() const
{
constPolish();
int l = 0;
int t = 0;
if ( children() ) {
const QObjectList * c = children();
QObjectListIt it( *c );
QObject * o;
while( (o=it.current()) != 0 ) {
++it;
if ( o->isWidgetType() &&
!((QWidget*)o)->isHidden() ) {
QSize s = ((QWidget*)o)->sizeHint();
if ( s.isValid() ) {
l += pick( s );
t = QMAX( t, trans( s ) );
}
}
}
}
return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l );
}
/*!
\reimp
*/
QSize QSplitter::minimumSizeHint() const
{
constPolish();
int l = 0;
int t = 0;
if ( children() ) {
const QObjectList * c = children();
QObjectListIt it( *c );
QObject * o;
while( (o=it.current()) != 0 ) {
++it;
if ( o->isWidgetType() &&
!((QWidget*)o)->isHidden() ) {
QSize s = minSize((QWidget*)o);
if ( s.isValid() ) {
l += pick( s );
t = QMAX( t, trans( s ) );
}
}
}
}
return orientation() == Horizontal ? QSize( l, t ) : QSize( t, l );
}
/*!\reimp
*/
QSizePolicy QSplitter::sizePolicy() const
{
return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
}
/*!
Calculates stretch parameters from current sizes
*/
void QSplitter::storeSizes()
{
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( !s->isSplitter )
s->sizer = pick( s->wid->size() );
s = data->list.next();
}
}
#if 0 // ### remove this code ASAP
/*!
Hides \a w if \a hide is TRUE, and updates the splitter.
\warning Due to a limitation in the current implementation,
calling QWidget::hide() will not work.
*/
void QSplitter::setHidden( QWidget *w, bool hide )
{
if ( w == w1 ) {
w1show = !hide;
} else if ( w == w2 ) {
w2show = !hide;
} else {
#ifdef CHECK_RANGE
qWarning( "QSplitter::setHidden(), unknown widget" );
#endif
return;
}
if ( hide )
w->hide();
else
w->show();
recalc( TRUE );
}
/*!
Returns the hidden status of \a w
*/
bool QSplitter::isHidden( QWidget *w ) const
{
if ( w == w1 )
return !w1show;
else if ( w == w2 )
return !w2show;
#ifdef CHECK_RANGE
else
qWarning( "QSplitter::isHidden(), unknown widget" );
#endif
return FALSE;
}
#endif
/*!
Returns a list of the size parameters of all the widgets in this
splitter.
Giving the values to setSizes() will give a splitter with the same
layout as this one.
\sa setSizes()
*/
QValueList<int> QSplitter::sizes() const
{
if ( !testWState(WState_Polished) ) {
QWidget* that = (QWidget*) this;
that->polish();
}
QValueList<int> list;
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( !s->isSplitter )
list.append( s->sizer );
s = data->list.next();
}
return list;
}
/*!
Sets the size parameters to the values given in \a list.
If the splitter is horizontal, the values set the sizes from
left to right. If it is vertical, the sizes are applied from
top to bottom.
Extra values in \a list are ignored.
If \a list contains too few values, the result is undefined
but the program will still be well-behaved.
\sa sizes()
*/
void QSplitter::setSizes( QValueList<int> list )
{
processChildEvents();
QValueList<int>::Iterator it = list.begin();
QSplitterLayoutStruct *s = data->list.first();
while ( s && it != list.end() ) {
if ( !s->isSplitter ) {
s->sizer = *it;
++it;
}
s = data->list.next();
}
doResize();
}
/*!
Gets all posted child events, ensuring that the internal state of
the splitter is consistent with the programmer's idea.
*/
void QSplitter::processChildEvents()
{
QApplication::sendPostedEvents( this, QEvent::ChildInserted );
}
/*!
\reimp
*/
void QSplitter::styleChange( QStyle& old )
{
int sw = style().splitterWidth();
QSplitterLayoutStruct *s = data->list.first();
while ( s ) {
if ( s->isSplitter )
s->sizer = sw;
s = data->list.next();
}
doResize();
QFrame::styleChange( old );
}