Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

remapdlg.cpp

Go to the documentation of this file.
00001 
00002 #include "remapdlg.h"
00003 #include "buttonutils.h"
00004 
00005 /* OPIE */
00006 #include <opie2/odebug.h>
00007 
00008 /* QT */
00009 #include <qlistview.h>
00010 #include <qcombobox.h>
00011 #include <qtimer.h>
00012 
00013 
00014 
00015 using namespace Opie::Core;
00016 class NoSortItem : public QListViewItem {
00017 public:
00018   NoSortItem ( QListView *lv, uint pos, const QString &str, const QCString &s1 = 0, const QCString &s2 = 0 )
00019     : QListViewItem ( lv, str, s1, s2 )
00020   {
00021     m_key = QString ( QChar ( 'a' + pos ));
00022     m_def = false;
00023   }
00024 
00025   void setDefault ( bool b )
00026   {
00027     m_def = b;
00028   }
00029 
00030   virtual QString key ( int /*column*/, bool /*ascending*/ ) const
00031   {
00032     return m_key;
00033   }
00034 
00035   virtual void paintCell ( QPainter * p, const QColorGroup & cg, int column, int width, int align )
00036   {
00037     if ( m_def ) {
00038       QFont f ( listView ( )-> font ( ));
00039       f. setBold ( true );
00040       p-> setFont ( f );
00041     }
00042     QListViewItem::paintCell ( p, cg, column, width, align );
00043   }
00044 
00045 private:
00046   QString m_key;
00047   bool m_def;
00048 };
00049 
00050 
00051 RemapDlg::RemapDlg ( const Opie::Core::ODeviceButton *b, bool hold, QWidget *parent, const char *name )
00052   : RemapDlgBase ( parent, name, true, WStyle_ContextHelp )
00053 {
00054   setCaption ( tr( "%1 %2", "(hold|press) buttoname" ). arg( hold ? tr( "Held" ) : tr( "Pressed" )). arg ( b-> userText ( )));
00055 
00056   m_current = 0;
00057 
00058   static const char * const def_channels [] = { "QPE/Application/", "QPE/Launcher", "QPE/System", "QPE/TaskBar", "QPE/", 0 };
00059   w_channel-> insertStrList ((const char **) def_channels );
00060 
00061   m_msg = hold ? b-> heldAction ( ) : b-> pressedAction ( );
00062   m_msg_preset = hold ? b-> factoryPresetHeldAction ( ) : b-> factoryPresetPressedAction ( );
00063 
00064   m_map_none   = new NoSortItem ( w_list, 0, tr( "No mapping" ));
00065   m_map_preset = new NoSortItem ( w_list, 1, tr( "Default" ), m_msg_preset. channel ( ), m_msg_preset. message ( ));
00066   ((NoSortItem *) m_map_preset )-> setDefault ( true );
00067 
00068   if (m_msg. channel ( ) == "ignore")
00069   {
00070     m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg_preset. channel ( ), m_msg_preset. message ( ));
00071 
00072     m_current = m_map_none;
00073   }
00074   else
00075   {
00076     m_map_custom = new NoSortItem ( w_list, 2, tr( "Custom" ), m_msg. channel ( ), m_msg. message ( ));
00077     m_current = m_map_custom;
00078   }
00079 
00080   QListViewItem *it = new NoSortItem ( w_list, 3, tr( "Actions" ));
00081   ButtonUtils::inst ( )-> insertActions ( it );
00082   it-> setOpen ( true );
00083 
00084   m_map_show = new NoSortItem ( w_list, 4, tr( "Show" ));
00085 
00086   w_list-> setCurrentItem ( m_current );
00087 
00088   QTimer::singleShot ( 0, this, SLOT( delayedInit()));
00089 }
00090 
00091 RemapDlg::~RemapDlg ( )
00092 {
00093 }
00094 
00095 void RemapDlg::delayedInit ( )
00096 {
00097   bool b = w_list-> viewport ( )-> isUpdatesEnabled ( );
00098   w_list-> viewport ( )-> setUpdatesEnabled ( false );
00099 
00100   ButtonUtils::inst ( )-> insertAppLnks ( m_map_show );
00101 
00102   w_list-> viewport ( )-> setUpdatesEnabled ( b );
00103 
00104   m_map_show-> repaint ( );
00105 }
00106 
00107 void RemapDlg::itemChanged ( QListViewItem *it )
00108 {
00109   bool enabled = false;
00110   OQCopMessage m;
00111 
00112   m_current = it;
00113 
00114   if ( it == m_map_none )
00115   {
00116     m_msg = m = OQCopMessage ( "ignore", 0 );
00117     odebug << "***ignoring" << oendl;
00118   }
00119   else if ( it == m_map_preset )
00120   {
00121     m_msg = m = m_msg_preset;
00122     odebug << "***Preset" << oendl;
00123   }
00124   else if ( it && !it-> childCount ( ) )
00125   {
00126     odebug << "***Custom: " << it-> text ( 1 ). latin1 ( ) << " " << it-> text ( 2 ). latin1 ( ) << oendl;
00127     enabled = ( it == m_map_custom );
00128     m_msg = m = OQCopMessage ( it-> text ( 1 ). latin1 ( ), it-> text ( 2 ). latin1 ( ));
00129   }
00130 
00131   w_channel-> setEnabled ( enabled );
00132   w_message-> setEnabled ( enabled );
00133 
00134   w_channel-> setEditText ( m. channel ( ));
00135 //hack for if user has typed in a message, such as 'suspend()'
00136 //so raise() is always present
00137   if(m. message ( ) != "raise()")
00138      w_message->insertItem("raise()");
00139   w_message-> setEditText ( m. message ( ));
00140 }
00141 
00142 void RemapDlg::textChanged ( const QString &str )
00143 {
00144    if ( !m_current )
00145     return;
00146 
00147   QComboBox *which = (QComboBox *) sender ( );
00148 
00149   if ( which == w_channel )
00150     m_current-> setText ( 1, str );
00151   else if ( which == w_message )
00152     m_current-> setText ( 2, str );
00153 }
00154 
00155 OQCopMessage RemapDlg::message ( )
00156 {
00157 //make sure to update message if typed in
00158    itemChanged(w_list->currentItem());
00159   return m_msg;
00160 }
00161 

Generated on Sat Nov 5 16:15:56 2005 for OPIE by  doxygen 1.4.2