summaryrefslogtreecommitdiff
path: root/noncore/apps/opie-reader/ButtonPrefs.cpp
blob: 762de554084b2bd60aef87c5550322f3324bdf62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
/****************************************************************************
** Form implementation generated from reading ui file 'Prefs.ui'
**
** Created: Tue Feb 11 23:53:35 2003
**      by:  The User Interface Compiler (uic)
**
** WARNING! All changes made in this file will be lost!
****************************************************************************/
#include "ButtonPrefs.h"

#include <qcheckbox.h>
#include <qlabel.h>
#include <qpushbutton.h>
#include <qspinbox.h>
#include <qlayout.h>
#include <qvariant.h>
#include <qtooltip.h>
#include <qwhatsthis.h>
#include <qbuttongroup.h>
#include <qmultilineedit.h>
#ifdef USECOMBO
#include <qcombobox.h>
#else
#include <qpe/menubutton.h>
#endif
#include <qfontdatabase.h>

#include <qlistview.h>

class MyQListViewItem : public QListViewItem
{
  orKey o;
public:
  MyQListViewItem(const orKey& _o, QListView* p, const QString& c1, const QString& c2, const QString& c3) : QListViewItem(p, c1, c2, c3), o(_o) { }
  orKey getKey() { return o; }
};

void CButtonPrefs::mapkey(Qt::ButtonState st, int _key)
{
  mapkey(st, _key,  action->currentItem());
}

void CButtonPrefs::mapkey(Qt::ButtonState st, int _key, int act)
{
  orKey key(st, _key, ((act == cesScrollMore) || (act == cesScrollLess)));
  QMap<orKey,QListViewItem*>::Iterator iter = listmap.find(key);
  if (iter != listmap.end())
    {
      lb->takeItem(iter.data());
    }
  (*kmap)[key] = act;
  listmap[key] = new MyQListViewItem(key, lb, key.text(), action->text(act), (key.isScroll()) ? "*":"");
}

void CButtonPrefs::keyPressEvent(QKeyEvent* e)
{
  switch (e->key())
    {
    case Key_Shift:
    case Key_Control:
    case Key_Meta:
    case Key_Alt:
    case Key_CapsLock:
    case Key_NumLock:
    case Key_ScrollLock:
      e->ignore();
      break;
    default:
      mapkey(e->state(), e->key());
      e->accept();
      break;
    }
}

#ifdef USECOMBO
void CButtonPrefs::populate(QComboBox *mb)
#else
void CButtonPrefs::populate(MenuButton *mb)
#endif
{
    mb->setSizePolicy(QSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed));
    mb->insertItem( tr("Open file") );
    mb->insertItem( tr("Autoscroll") );
    mb->insertItem( tr("Bookmark") );
    mb->insertItem( tr("Annotate") );
    mb->insertItem( tr("Fullscreen") );

    mb->insertItem( tr("Zoom in") );
    mb->insertItem( tr("Zoom out") );
    mb->insertItem( tr("Back") );
    mb->insertItem( tr("Forward") );
    mb->insertItem( tr("Home") );
    mb->insertItem( tr("Page up") );
    mb->insertItem( tr("Page down") );
    mb->insertItem( tr("Line up") );
    mb->insertItem( tr("Line down") );
    mb->insertItem( tr("Beginning") );
    mb->insertItem( tr("End") );
    mb->insertItem( tr("Rotate") );
    mb->insertItem( tr("Scroll faster") );
    mb->insertItem( tr("Scroll slower") );
    mb->insertItem( tr("Invert colours") );
    mb->insertItem( tr("Toggle tools") );
    mb->insertItem( tr("Toggle scrollbar") );
    mb->insertItem( tr("Toggle statusbar") );
    mb->insertItem( tr("Next link") );
    mb->insertItem( tr("Goto link") );
}

CButtonPrefs::CButtonPrefs( QMap<orKey, int>* _kmap, QWidget* parent,  const char* name, WFlags fl )
  : QWidget( parent, name, fl ), kmap(_kmap)
{
  QVBoxLayout* vo = new QVBoxLayout(this);
  QHBoxLayout* lo = new QHBoxLayout();
  setFocusPolicy(QWidget::StrongFocus);
#ifdef USECOMBO
    action = new QComboBox( this );
#else
    action = new MenuButton( this );
#endif
    populate(action);
    action->setFocusProxy(this);



    QMultiLineEdit* TextLabel1 = new QMultiLineEdit( this );
    TextLabel1->setText( tr( "Press the key(s) you want assigned to the highlighted function.\n\nPress the delete button to unmap the key.\n\nUse the \"Close\" button (not the [x]) to finish." ) );
    TextLabel1->setReadOnly(true);
    TextLabel1->setWordWrap(QMultiLineEdit::WidgetWidth);

    //    lo->addWidget(TextLabel, 0, Qt::AlignTop);
    //    lo->addWidget(action, 0, Qt::AlignTop);
    lo->addWidget(TextLabel1);
    lo->addWidget(action);
    vo->addLayout(lo);
    lb = new QListView(this);
    lb->addColumn( tr( "Key" ) );
    lb->addColumn( tr( "Function" ) );
    lb->addColumn( tr( "Scroll" ) );
    lb->setFocusProxy(this);
    vo->addWidget(lb,1);
    for (QMap<orKey,int>::Iterator i = kmap->begin(); i != kmap->end(); i++)
      {
	listmap[i.key()] = new MyQListViewItem(i.key(), lb, i.key().text(), action->text(i.data()), (i.key().isScroll()) ? "*":"");
      }

    lo = new QHBoxLayout();
    QLabel* TextLabel = new QLabel( this, "TextLabel1" );
    TextLabel->setText( tr( "Debounce" ) );
    lo->addWidget(TextLabel);

    debounce = new QSpinBox( this, "Debounce" );
    debounce->setRange(0,1000);
    lo->addWidget(debounce);
    /*
    QPushButton* assignClose = new QPushButton("Assign\nCancel", this);
    lo->addWidget(assignClose);
    */
    lo->addStretch(1);
    QPushButton* delButton = new QPushButton("Delete", this);
    connect(delButton, SIGNAL( clicked() ), this, SLOT( erasemapping() ));
    lo->addWidget(delButton);     
    QPushButton* exitButton = new QPushButton("Close", this);
    connect(exitButton, SIGNAL( clicked() ), this, SLOT( slotClosed() ) );
    lo->addWidget(exitButton);     
    vo->addLayout(lo);
}

void CButtonPrefs::erasemapping()
{
  MyQListViewItem* li = (MyQListViewItem*)lb->selectedItem();
  if (li != NULL)
    {
      orKey key(li->getKey());
      qDebug("Tapped %s", (const char*)key.text());
      kmap->remove(key);
      lb->takeItem(listmap[key]);
      listmap.remove(key);
    }
}

CButtonPrefs::~CButtonPrefs()
{
    // no need to delete child widgets, Qt does it all for us
}