summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--core/settings/button/buttonsettings.cpp8
-rw-r--r--core/settings/button/buttonsettings.h1
-rw-r--r--core/settings/button/buttonutils.cpp22
-rw-r--r--core/settings/button/remapdlg.cpp27
-rw-r--r--core/settings/button/remapdlg.h4
5 files changed, 48 insertions, 14 deletions
diff --git a/core/settings/button/buttonsettings.cpp b/core/settings/button/buttonsettings.cpp
index c71514c..8b0b0a8 100644
--- a/core/settings/button/buttonsettings.cpp
+++ b/core/settings/button/buttonsettings.cpp
@@ -15,235 +15,243 @@
    =_        +     =;=|` 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 <qlayout.h>
#include <qlabel.h>
#include <qtimer.h>
#include <qpe/qpeapplication.h>
#include <opie/odevice.h>
#include "buttonsettings.h"
#include "buttonutils.h"
#include "remapdlg.h"
using namespace Opie;
struct buttoninfo {
const ODeviceButton *m_button;
int m_index;
OQCopMessage m_pmsg;
QLabel *m_picon;
QLabel *m_plabel;
OQCopMessage m_hmsg;
QLabel *m_hicon;
QLabel *m_hlabel;
bool m_pdirty : 1;
bool m_hdirty : 1;
};
ButtonSettings::ButtonSettings ( )
: QDialog ( 0, "ButtonSettings", false, WStyle_ContextHelp )
{
const QValueList <ODeviceButton> &buttons = ODevice::inst ( )-> buttons ( );
+ (void) ButtonUtils::inst ( ); // initialise
setCaption ( tr( "Button Settings" ));
QVBoxLayout *toplay = new QVBoxLayout ( this, 3, 3 );
QLabel *l = new QLabel ( tr( "<center>Press or hold the button you want to remap.</center>" ), this );
toplay-> addWidget ( l );
QGridLayout *lay = new QGridLayout ( toplay );
lay-> setMargin ( 0 );
lay-> setColStretch ( 0, 0 );
lay-> setColStretch ( 1, 0 );
lay-> setColStretch ( 2, 0 );
lay-> setColStretch ( 3, 10 );
m_infos. setAutoDelete ( true );
int i = 1;
int index = 0;
for ( QValueList<ODeviceButton>::ConstIterator it = buttons. begin ( ); it != buttons. end ( ); it++ ) {
if ( it != buttons. begin ( )) {
QFrame *f = new QFrame ( this );
f-> setFrameStyle ( QFrame::Sunken | QFrame::VLine );
lay-> addMultiCellWidget ( f, i, i, 0, 2 );
i++;
}
buttoninfo *bi = new buttoninfo ( );
bi-> m_button = &(*it);
bi-> m_index = index++;
bi-> m_pmsg = (*it). pressedAction ( );
bi-> m_hmsg = (*it). heldAction ( );
bi-> m_pdirty = false;
bi-> m_hdirty = false;
l = new QLabel ( this );
l-> setPixmap (( *it ). pixmap ( ));
lay-> addMultiCellWidget ( l, i, i + 1, 0, 0 );
l = new QLabel ( tr( "Press:" ), this );
lay-> addWidget ( l, i, 1, AlignLeft | AlignBottom );
l = new QLabel ( tr( "Hold:" ), this );
lay-> addWidget ( l, i + 1, 1, AlignLeft | AlignTop );
l = new QLabel ( this );
l-> setFixedSize ( 16, 16 );
lay-> addWidget ( l, i, 2, AlignLeft | AlignBottom );
bi-> m_picon = l;
l = new QLabel ( this );
l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine );
lay-> addWidget ( l, i, 3, AlignLeft | AlignBottom );
bi-> m_plabel = l;
l = new QLabel ( this );
l-> setFixedSize ( 16, 16 );
lay-> addWidget ( l, i + 1, 2, AlignLeft | AlignTop );
bi-> m_hicon = l;
l = new QLabel ( this );
l-> setAlignment ( AlignLeft | AlignVCenter | SingleLine );
lay-> addWidget ( l, i + 1, 3, AlignLeft | AlignTop );
bi-> m_hlabel = l;
i += 2;
m_infos. append ( bi );
}
toplay-> addStretch ( 10 );
m_last_button = 0;
+ m_lock = false;
m_timer = new QTimer ( this );
connect ( m_timer, SIGNAL( timeout ( )), this, SLOT( keyTimeout ( )));
updateLabels ( );
QPEApplication::grabKeyboard ( );
}
ButtonSettings::~ButtonSettings ( )
{
QPEApplication::ungrabKeyboard ( );
}
void ButtonSettings::updateLabels ( )
{
for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) {
qCopInfo cip = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_pmsg );
(*it)-> m_picon-> setPixmap ( cip. m_icon );
(*it)-> m_plabel-> setText ( cip. m_name );
qCopInfo cih = ButtonUtils::inst ( )-> messageToInfo ((*it)-> m_hmsg );
(*it)-> m_hicon-> setPixmap ( cih. m_icon );
(*it)-> m_hlabel-> setText ( cih. m_name );
}
}
buttoninfo *ButtonSettings::buttonInfoForKeycode ( ushort key )
{
for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) {
if ((*it)-> m_button-> keycode ( ) == key )
return *it;
}
return 0;
}
void ButtonSettings::keyPressEvent ( QKeyEvent *e )
{
buttoninfo *bi = buttonInfoForKeycode ( e-> key ( ));
if ( bi && !e-> isAutoRepeat ( )) {
m_timer-> stop ( );
m_last_button = bi;
m_timer-> start ( ODevice::inst ( )-> buttonHoldTime ( ), true );
}
else
QDialog::keyPressEvent ( e );
}
void ButtonSettings::keyReleaseEvent ( QKeyEvent *e )
{
buttoninfo *bi = buttonInfoForKeycode ( e-> key ( ));
if ( bi && !e-> isAutoRepeat ( ) && m_timer-> isActive ( )) {
m_timer-> stop ( );
edit ( bi, false );
}
else
QDialog::keyReleaseEvent ( e );
}
void ButtonSettings::keyTimeout ( )
{
if ( m_last_button ) {
edit ( m_last_button, true );
m_last_button = false;
}
}
void ButtonSettings::edit ( buttoninfo *bi, bool hold )
{
qDebug ( "remap %s for %s", hold ? "hold" : "press", bi-> m_button-> userText ( ). latin1 ( ));
+ if ( m_lock )
+ return;
+ m_lock = true;
+
RemapDlg *d = new RemapDlg ( bi-> m_button, hold, this );
d-> showMaximized ( );
if ( d-> exec ( ) == QDialog::Accepted ) {
qDebug ( " -> %s %s", d-> message ( ). channel ( ). data ( ), d-> message ( ). message ( ). data ( ));
if ( hold ) {
bi-> m_hmsg = d-> message ( );
bi-> m_hdirty = true;
}
else {
bi-> m_pmsg = d-> message ( );
bi-> m_pdirty = true;
}
updateLabels ( );
}
delete d;
+
+ m_lock = false;
}
void ButtonSettings::accept ( )
{
for ( QListIterator <buttoninfo> it ( m_infos ); *it; ++it ) {
buttoninfo *bi = *it;
if ( bi-> m_pdirty )
ODevice::inst ( )-> remapPressedAction ( bi-> m_index, bi-> m_pmsg );
if ( bi-> m_hdirty )
ODevice::inst ( )-> remapHeldAction ( bi-> m_index, bi-> m_hmsg );
}
QDialog::accept ( );
}
void ButtonSettings::done ( int r )
{
QDialog::done ( r );
close ( );
}
diff --git a/core/settings/button/buttonsettings.h b/core/settings/button/buttonsettings.h
index f571825..d41a209 100644
--- a/core/settings/button/buttonsettings.h
+++ b/core/settings/button/buttonsettings.h
@@ -22,53 +22,54 @@
    --        :-=` Free Software Foundation, Inc.,
59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#ifndef __BUTTON_SETTINGS_H__
#define __BUTTON_SETTINGS_H__
#include <qdialog.h>
#include <qlist.h>
#include <opie/odevice.h>
class QTimer;
using namespace Opie;
class buttoninfo;
class ButtonSettings : public QDialog {
Q_OBJECT
public:
ButtonSettings ( );
~ButtonSettings ( );
virtual void accept ( );
virtual void done ( int r );
private slots:
void keyTimeout ( );
void updateLabels ( );
protected:
virtual void keyPressEvent ( QKeyEvent *e );
virtual void keyReleaseEvent ( QKeyEvent *e );
private:
buttoninfo *buttonInfoForKeycode ( ushort key );
void edit ( buttoninfo *bi, bool hold );
QString qcopToString ( const OQCopMessage &c );
private:
QTimer *m_timer;
buttoninfo *m_last_button;
QList <buttoninfo> m_infos;
+ bool m_lock;
};
#endif
diff --git a/core/settings/button/buttonutils.cpp b/core/settings/button/buttonutils.cpp
index bb70047..91d2af3 100644
--- a/core/settings/button/buttonutils.cpp
+++ b/core/settings/button/buttonutils.cpp
@@ -56,64 +56,72 @@ ButtonUtils::ButtonUtils ( )
}
ButtonUtils::~ButtonUtils ( )
{
delete m_apps;
}
qCopInfo ButtonUtils::messageToInfo ( const OQCopMessage &c )
{
QCString ch = c. channel ( );
QCString f = c. message ( );
if ( ch. isNull ( ))
return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Ignored</nobr>" ));
for ( const predef_qcop *p = predef; p-> m_text; p++ ) {
if (( ch == p-> m_channel ) && ( f == p-> m_function ))
return qCopInfo ( qApp-> translate ( "ButtonSettings", p-> m_text ), Resource::loadPixmap ( p-> m_pixmap ));
}
if ( ch. left ( 16 ) == "QPE/Application/" ) {
QString app = ch. mid ( 16 );
const AppLnk *applnk = m_apps-> findExec ( app );
if ( applnk )
app = applnk-> name ( );
if (( f == "raise()" ) || ( f == "nextView()" ))
return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Show <b>%1</b></nobr>" ). arg ( app ), applnk ? applnk-> pixmap ( ) : QPixmap ( ));
else
return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Call <b>%1</b>: <i>%2</i></nobr>" ). arg ( app ). arg ( f ), applnk ? applnk-> pixmap ( ) : QPixmap ( ));
}
else {
return qCopInfo ( qApp-> translate ( "ButtonSettings", "<nobr>Call <b>%1</b> <i>%2</i></nobr>" ). arg (( ch. left ( 4 ) == "QPE/" ) ? ch. mid ( 4 ) : ch ). arg ( f ));
}
}
void ButtonUtils::insertActions ( QListViewItem *here )
{
for ( const predef_qcop *p = predef; p-> m_text; p++ ) {
QListViewItem *item = new QListViewItem ( here, qApp-> translate ( "ButtonSettings", p-> m_text ), p-> m_channel, p-> m_function );
item-> setPixmap ( 0, Resource::loadPixmap ( p-> m_pixmap ));
}
}
void ButtonUtils::insertAppLnks ( QListViewItem *here )
{
- QStringList types = m_apps-> types ( );
+ QStringList types = m_apps-> types ( );
+ QListViewItem *typeitem [types. count ( )];
+ int i = 0;
for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) {
QListViewItem *item = new QListViewItem ( here, m_apps-> typeName ( *it ));
item-> setPixmap ( 0, m_apps-> typePixmap ( *it ));
-
- for ( QListIterator <AppLnk> appit ( m_apps-> children ( )); *appit; ++appit ) {
- AppLnk *l = *appit;
-
+
+ typeitem [i++] = item;
+ }
+
+ for ( QListIterator <AppLnk> appit ( m_apps-> children ( )); *appit; ++appit ) {
+ AppLnk *l = *appit;
+
+ int i = 0;
+ for ( QStringList::Iterator it = types. begin ( ); it != types. end ( ); ++it ) {
if ( l-> type ( ) == *it ) {
- QListViewItem *sub = new QListViewItem ( item, l-> name ( ), QString ( "QPE/Application/" ) + l-> exec ( ), "raise()" );
+ QListViewItem *sub = new QListViewItem ( typeitem [i], l-> name ( ), QString ( "QPE/Application/" ) + l-> exec ( ), "raise()" );
sub-> setPixmap ( 0, l-> pixmap ( ));
}
- }
+ i++;
+ }
}
}
diff --git a/core/settings/button/remapdlg.cpp b/core/settings/button/remapdlg.cpp
index 511d0e7..a251bd4 100644
--- a/core/settings/button/remapdlg.cpp
+++ b/core/settings/button/remapdlg.cpp
@@ -1,119 +1,132 @@
#include <qlistview.h>
#include <qlabel.h>
#include <qcombobox.h>
+#include <qtimer.h>
#include "remapdlg.h"
#include "buttonutils.h"
using namespace Opie;
class NoSortItem : public QListViewItem {
public:
NoSortItem ( QListView *lv, uint pos, const QString &str, const QCString &s1 = 0, const QCString &s2 = 0 )
: QListViewItem ( lv, str, s1, s2 )
{
m_key = QString ( QChar ( 'a' + pos ));
m_def = false;
}
void setDefault ( bool b )
{
m_def = b;
}
virtual QString key ( int /*column*/, bool /*ascending*/ ) const
{
return m_key;
}
virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align )
{
if ( m_def ) {
QFont f ( listView ( )-> font ( ));
f. setBold ( true );
p-> setFont ( f );
}
QListViewItem::paintCell ( p, cg, column, width, align );
}
private:
QString m_key;
bool m_def;
};
RemapDlg::RemapDlg ( const Opie::ODeviceButton *b, bool hold, QWidget *parent, const char *name )
: RemapDlgBase ( parent, name, true, WStyle_ContextHelp )
{
setCaption ( tr( "%1 %2", "(hold|press) buttoname" ). arg( hold ? tr( "Held" ) : tr( "Pressed" )). arg ( b-> userText ( )));
+
+ m_current = 0;
+
+ static const char * const def_channels [] = { "QPE/Application/", "QPE/Launcher", "QPE/System", "QPE/TaskBar", "QPE/", 0 };
+ w_channel-> insertStrList ((const char **) def_channels );
m_msg = hold ? b-> heldAction ( ) : b-> pressedAction ( );
m_msg_preset = hold ? b-> factoryPresetHeldAction ( ) : b-> factoryPresetPressedAction ( );
m_map_none = new NoSortItem ( w_list, 0, tr( "No mapping" ));
m_map_preset = new NoSortItem ( w_list, 1, tr( "Default" ), m_msg_preset. channel ( ), m_msg_preset. message ( ));
((NoSortItem *) m_map_preset )-> setDefault ( true );
m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg. channel ( ), m_msg. message ( ));
QListViewItem *it = new NoSortItem ( w_list, 3, tr( "Actions" ));
ButtonUtils::inst ( )-> insertActions ( it );
it-> setOpen ( true );
- it = new NoSortItem ( w_list, 4, tr( "Show" ));
- ButtonUtils::inst ( )-> insertAppLnks ( it );
+ m_map_show = new NoSortItem ( w_list, 4, tr( "Show" ));
m_current = m_map_custom;
w_list-> setCurrentItem ( m_current );
- static const char * const def_channels [] = {
- "QPE/Application/", "QPE/Launcher", "QPE/System", "QPE/TaskBar", "QPE/", 0
- };
-
- w_channel-> insertStrList ((const char **) def_channels );
+ QTimer::singleShot ( 0, this, SLOT( delayedInit ( )));
}
RemapDlg::~RemapDlg ( )
{
}
+void RemapDlg::delayedInit ( )
+{
+ bool b = w_list-> viewport ( )-> isUpdatesEnabled ( );
+ w_list-> viewport ( )-> setUpdatesEnabled ( false );
+
+ ButtonUtils::inst ( )-> insertAppLnks ( m_map_show );
+
+ w_list-> viewport ( )-> setUpdatesEnabled ( b );
+
+ m_map_show-> repaint ( );
+}
+
void RemapDlg::itemChanged ( QListViewItem *it )
{
bool enabled = false;
OQCopMessage m;
m_current = it;
if ( it == m_map_none )
m_msg = m = OQCopMessage ( 0, 0 );
else if ( it == m_map_preset )
m_msg = m = m_msg_preset;
else if ( it && !it-> childCount ( )) {
enabled = ( it == m_map_custom );
m_msg = m = OQCopMessage ( it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( ));
}
w_channel-> setEnabled ( enabled );
w_message-> setEnabled ( enabled );
w_channel-> setEditText ( m. channel ( ));
w_message-> setEditText ( m. message ( ));
}
void RemapDlg::textChanged ( const QString &str )
{
if ( !m_current )
return;
QComboBox *which = (QComboBox *) sender ( );
if ( which == w_channel )
m_current-> setText ( 1, str );
else if ( which == w_message )
m_current-> setText ( 2, str );
}
OQCopMessage RemapDlg::message ( )
{
return m_msg;
}
diff --git a/core/settings/button/remapdlg.h b/core/settings/button/remapdlg.h
index 8c9cc02..046a22f 100644
--- a/core/settings/button/remapdlg.h
+++ b/core/settings/button/remapdlg.h
@@ -1,35 +1,39 @@
#ifndef __REMAPDLG_H__
#define __REMAPDLG_H__
#include <opie/odevicebutton.h>
#include "remapdlgbase.h"
class QListViewItem;
class RemapDlg : public RemapDlgBase {
Q_OBJECT
public:
RemapDlg ( const Opie::ODeviceButton *b, bool hold, QWidget* parent = 0, const char* name = 0 );
~RemapDlg ( );
Opie::OQCopMessage message ( );
public slots:
virtual void itemChanged ( QListViewItem * );
virtual void textChanged ( const QString & );
+
+private slots:
+ void delayedInit ( );
private:
Opie::OQCopMessage m_msg;
Opie::OQCopMessage m_msg_preset;
QListViewItem *m_current;
QListViewItem *m_map_none;
QListViewItem *m_map_preset;
QListViewItem *m_map_custom;
+ QListViewItem *m_map_show;
};
#endif