author | zecke <zecke> | 2004-09-06 23:51:20 (UTC) |
---|---|---|
committer | zecke <zecke> | 2004-09-06 23:51:20 (UTC) |
commit | e6798d7ec0a3b86e412bd67faad24a737a67aa5f (patch) (side-by-side diff) | |
tree | ff10e927aff440d8dca2e0fe8976aadb3ff011d2 | |
parent | 8f18e8b46dfaaa7e03b9ed1f3faed12da5b30cd5 (diff) | |
download | opie-e6798d7ec0a3b86e412bd67faad24a737a67aa5f.zip opie-e6798d7ec0a3b86e412bd67faad24a737a67aa5f.tar.gz opie-e6798d7ec0a3b86e412bd67faad24a737a67aa5f.tar.bz2 |
Use OKeyConfigWidget/Manager for managing next and prev tab
keyboard shortcuts
-rw-r--r-- | noncore/net/opieirc/ircmisc.cpp | 44 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.h | 14 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsettings.cpp | 20 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsettings.h | 4 | ||||
-rw-r--r-- | noncore/net/opieirc/irctab.cpp | 9 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.cpp | 1 |
6 files changed, 84 insertions, 8 deletions
diff --git a/noncore/net/opieirc/ircmisc.cpp b/noncore/net/opieirc/ircmisc.cpp index df6f874..9b9bff8 100644 --- a/noncore/net/opieirc/ircmisc.cpp +++ b/noncore/net/opieirc/ircmisc.cpp @@ -1,22 +1,25 @@ #include "ircmisc.h" /* OPIE */ #include <opie2/odebug.h> +#include <opie2/oconfig.h> +#include <opie2/okeyconfigmanager.h> using namespace Opie::Core; + IRCTabBar::IRCTabBar(QWidget *parent, const char *name) : QTabBar(parent, name) { } int IRCTabBar::insertTab(QTab *tab, int index) { /* FIXME: find some nicer way to do this */ QExtTab *ext = new QExtTab(); ext->color = black; ext->label = tab->text(); ext->r = tab->rect(); ext->enabled = tab->isEnabled(); ext->iconset = tab->iconSet(); delete tab; return QTabBar::insertTab(ext, index); } void IRCTabBar::setTabColor(int index, QColor color) { @@ -29,65 +32,96 @@ void IRCTabBar::paintLabel(QPainter* p, const QRect& br, QTab* t, bool focus) co QTabBar::paintLabel(p, br, t, focus); if (t->id == currentTab()) r.setBottom(r.bottom() - style().defaultFrameWidth()); p->setPen(((QExtTab *)t)->color); p->drawText(r, AlignCenter | ShowPrefix, t->label); } IRCTabWidget::IRCTabWidget(QWidget *parent, const char *name) : QTabWidget(parent, name) { setTabBar(new IRCTabBar(this, "tab control")); } void IRCTabWidget::setTabColor(int index, QColor color) { ((IRCTabBar *)tabBar())->setTabColor(index, color); } + +static OKeyConfigManager* s_manager = 0; +OKeyConfigManager* IRCHistoryLineEdit::keyConfigInstance() { + if ( !s_manager ) { + /* + * black list with the DeviceButtons as default + * because we do not grab the keyboard and they + * wouldn't work + */ + OKeyPair::List blackList = OKeyPair::hardwareKeys(); + blackList.append( OKeyPair::returnKey() ); + blackList.append( OKeyPair::leftArrowKey() ); + blackList.append( OKeyPair::upArrowKey() ); + blackList.append( OKeyPair::downArrowKey() ); + + s_manager = new OKeyConfigManager(new OConfig("opieirc-keys"), + "keys", blackList, + false, 0, "irc_history_line_keyconfigm" ); + s_manager->addKeyConfig( OKeyConfigItem( tr("Next Tab"), "next_tab", QPixmap(), + KeyNextTab, OKeyPair(Qt::Key_N, Qt::ControlButton) )); + s_manager->addKeyConfig( OKeyConfigItem( tr("Previous Tab"), "prev_tab", QPixmap(), + KeyPrevTab, OKeyPair(Qt::Key_P, Qt::ControlButton) )); + s_manager->load(); + } + + return s_manager; +} + + IRCHistoryLineEdit::IRCHistoryLineEdit(QWidget *parent, const char *name) : QLineEdit(parent, name) { m_index = -1; installEventFilter(this); } void IRCHistoryLineEdit::keyPressEvent(QKeyEvent *event) { int key = event->key(); if (key == Key_Up) { if (m_history.count() > 0 && m_index < (signed int)m_history.count()-1) { m_index++; setText(m_history[m_index]); } } else if (key == Key_Down) { if (m_history.count() > 0 && m_index > 0) { m_index--; setText(m_history[m_index]); } if (m_index == 0) { m_index = -1; setText(""); } } else if (key == Key_Return) { m_history.prepend(text()); m_index = -1; - } else if (key == Key_N && event->state() == Qt::ControlButton) { + } + + switch( keyConfigInstance()->handleKeyEventId( event ) ) { + case KeyNextTab: emit nextTab(); return; - } else if ( ( key == Key_Y || key == Key_Z ) && event->state() == Qt::ControlButton) { - emit closeTab(); - return; - } else if (key == Key_P && event->state() == Qt::ControlButton) { + case KeyPrevTab: emit prevTab(); return; + default: + break; } QLineEdit::keyPressEvent(event); } bool IRCHistoryLineEdit::eventFilter(QObject *object, QEvent *event) { if (event->type() == QEvent::KeyPress) { QKeyEvent *k = (QKeyEvent *) event; /* Catch tab characters */ if (k->key() == Key_Tab) { emit nextTab(); return TRUE; } } return QLineEdit::eventFilter(object, event); } diff --git a/noncore/net/opieirc/ircmisc.h b/noncore/net/opieirc/ircmisc.h index c42dcbd..37eed28 100644 --- a/noncore/net/opieirc/ircmisc.h +++ b/noncore/net/opieirc/ircmisc.h @@ -15,63 +15,77 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCMISC_H #define __IRCMISC_H #include <qtabwidget.h> #include <qlineedit.h> #include <qtabbar.h> #include <qlabel.h> #include <qcolor.h> #include <qarray.h> +namespace Opie { +namespace Core { +class OKeyConfigManager; +} +} + + /* Custom colored QTabWidget */ class QExtTab : public QTab { public: QColor color; }; class IRCTabWidget : public QTabWidget { Q_OBJECT public: IRCTabWidget(QWidget *parent = 0, const char *name = 0); void setTabColor(int index, QColor color); }; class IRCTabBar : public QTabBar { Q_OBJECT public: IRCTabBar(QWidget *parent = 0, const char *name = 0); void setTabColor(int index, QColor color); protected: void paintLabel(QPainter*, const QRect&, QTab*, bool) const; int insertTab(QTab *, int index = -1); protected: QArray<QColor> m_colors; }; /* A QLineEdit with history functionality and tab completion */ class IRCHistoryLineEdit : public QLineEdit { Q_OBJECT public: + enum KeyMode { + KeyNextTab, + KeyPrevTab + }; + + static Opie::Core::OKeyConfigManager* keyConfigInstance(); + IRCHistoryLineEdit(QWidget *parent = 0, const char *name = 0); virtual bool eventFilter(QObject *object, QEvent *event); public slots: void setEditFocus(); signals: void nextTab(); void prevTab(); void closeTab(); protected: void keyPressEvent(QKeyEvent *); protected: QStringList m_history; int m_index; }; diff --git a/noncore/net/opieirc/ircsettings.cpp b/noncore/net/opieirc/ircsettings.cpp index 13fcc24..1fba030 100644 --- a/noncore/net/opieirc/ircsettings.cpp +++ b/noncore/net/opieirc/ircsettings.cpp @@ -1,23 +1,25 @@ #include "ircsettings.h" #include "irctab.h" +#include "ircmisc.h" /* OPIE */ #include <opie2/ocolorbutton.h> #include <opie2/otabwidget.h> +#include <opie2/okeyconfigwidget.h> #include <qpe/qpeapplication.h> /* QT */ #include <qvalidator.h> #include <qwhatsthis.h> using namespace Opie; using namespace Opie::Ui; IRCSettings::IRCSettings(QWidget* parent, const char* name, bool modal, WFlags) : QDialog(parent, name, modal, WStyle_ContextHelp) { setCaption(tr("Settings") ); m_config = new Config("OpieIRC"); m_config->setGroup("OpieIRC"); QHBoxLayout *l = new QHBoxLayout(this, 2, 2); OTabWidget *tw = new OTabWidget(this); l->addWidget(tw); @@ -65,46 +67,62 @@ IRCSettings::IRCSettings(QWidget* parent, const char* name, bool modal, WFlags) label = new QLabel(tr("Text written by others :"), widget); layout->addWidget(label, 4, 0); m_other = new OColorButton(widget, m_config->readEntry("OtherColor", "#0000BB")); QWhatsThis::add(m_other, tr("Text color to be used to identify text written by others")); layout->addWidget(m_other, 4, 1); label = new QLabel(tr("Text written by the server :"), widget); layout->addWidget(label, 5, 0); m_server = new OColorButton(widget, m_config->readEntry("ServerColor", "#0000FF")); QWhatsThis::add(m_server, tr("Text color to be used to identify text written by the server")); layout->addWidget(m_server, 5, 1); label = new QLabel(tr("Notifications :"), widget); layout->addWidget(label, 6, 0); m_notification = new OColorButton(widget, m_config->readEntry("NotificationColor", "#AAE300")); QWhatsThis::add(m_notification, tr("Text color to be used to display notifications")); layout->addWidget(m_notification, 6, 1); tw->addTab(view, "opieirc/colors", tr("Colors")); - tw->setCurrentTab( genwidget ); + + /* + * IRC EditLine KeyConfiguration + */ + m_keyConf = new Opie::Ui::OKeyConfigWidget(tw, "KEyConfig GUI" ); + m_keyConf->setChangeMode( OKeyConfigWidget::Queue ); + m_keyConf->insert( tr("Keyboard Shortcuts"), + IRCHistoryLineEdit::keyConfigInstance() ); + m_keyConf->load(); + tw->addTab(m_keyConf, "SettingsIcon", tr("Keyboard Shortcuts") ); + + tw->setCurrentTab( genwidget ); QPEApplication::showDialog( this ); } void IRCSettings::accept() { IRCTab::m_backgroundColor = m_background->color().name(); IRCTab::m_textColor = m_text->color().name(); IRCTab::m_errorColor = m_error->color().name(); IRCTab::m_selfColor = m_self->color().name(); IRCTab::m_otherColor = m_other->color().name(); IRCTab::m_serverColor = m_server->color().name(); IRCTab::m_notificationColor = m_notification->color().name(); IRCTab::m_maxLines = m_lines->text().toInt(); + m_keyConf->save(); + + m_config->writeEntry("BackgroundColor", IRCTab::m_backgroundColor); m_config->writeEntry("TextColor", IRCTab::m_textColor); m_config->writeEntry("ErrorColor", IRCTab::m_errorColor); m_config->writeEntry("SelfColor", IRCTab::m_selfColor); m_config->writeEntry("OtherColor", IRCTab::m_otherColor); m_config->writeEntry("ServerColor", IRCTab::m_serverColor); m_config->writeEntry("NotificationColor", IRCTab::m_notificationColor); m_config->writeEntry("Lines", m_lines->text()); + IRCHistoryLineEdit::keyConfigInstance()->save(); + QDialog::accept(); } IRCSettings::~IRCSettings() { delete m_config; } diff --git a/noncore/net/opieirc/ircsettings.h b/noncore/net/opieirc/ircsettings.h index 56e667b..a032aff 100644 --- a/noncore/net/opieirc/ircsettings.h +++ b/noncore/net/opieirc/ircsettings.h @@ -14,38 +14,42 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #ifndef __IRCSETTINGS_H #define __IRCSETTINGS_H #include <qpe/config.h> #include <qdialog.h> #include <qlineedit.h> namespace Opie { class OColorButton; +namespace Ui { +class OKeyConfigWidget; +} } class IRCSettings : public QDialog { Q_OBJECT public: IRCSettings(QWidget* parent = 0, const char* name = 0, bool modal = FALSE, WFlags f = 0); ~IRCSettings(); protected slots: void accept(); protected: Config *m_config; Opie::OColorButton *m_background; Opie::OColorButton *m_text; Opie::OColorButton *m_error; Opie::OColorButton *m_self; Opie::OColorButton *m_server; Opie::OColorButton *m_other; Opie::OColorButton *m_notification; + Opie::Ui::OKeyConfigWidget *m_keyConf; QLineEdit *m_lines; }; #endif /* __IRCSETTINGS_H */ diff --git a/noncore/net/opieirc/irctab.cpp b/noncore/net/opieirc/irctab.cpp index 8e1dc16..2b3ecd4 100644 --- a/noncore/net/opieirc/irctab.cpp +++ b/noncore/net/opieirc/irctab.cpp @@ -1,21 +1,26 @@ +#include "irctab.h" +#include "mainwindow.h" + +#include <opie2/okeyconfigmanager.h> #include <qpe/resource.h> + + #include <qpushbutton.h> #include <qwhatsthis.h> -#include "irctab.h" -#include "mainwindow.h" + QString IRCTab::m_errorColor; QString IRCTab::m_serverColor; QString IRCTab::m_textColor; QString IRCTab::m_backgroundColor; QString IRCTab::m_selfColor; QString IRCTab::m_otherColor; QString IRCTab::m_notificationColor; int IRCTab::m_maxLines; IRCTab::IRCTab(QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) { m_layout = new QVBoxLayout(this); QHBoxLayout *descLayout = new QHBoxLayout(m_layout); descLayout->setMargin(5); m_description = new QLabel(tr("Missing description"), this); QWhatsThis::add(m_description, tr("Description of the tab's content")); diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp index 1143213..2e674c5 100644 --- a/noncore/net/opieirc/mainwindow.cpp +++ b/noncore/net/opieirc/mainwindow.cpp @@ -63,32 +63,33 @@ void MainWindow::addTab(IRCTab *tab) { connect(tab, SIGNAL(closeTab()), this, SLOT(slotCloseTab())); m_tabWidget->addTab(tab, tab->title()); m_tabWidget->showPage(tab); tab->setID(m_tabWidget->currentPageIndex()); m_tabs.append(tab); } void MainWindow::changeEvent(IRCTab *tab) { if (tab->id() != m_tabWidget->currentPageIndex()) m_tabWidget->setTabColor(tab->id(), blue); } void MainWindow::killTab(IRCTab *tab) { m_tabWidget->removePage(tab); m_tabs.remove(tab); + /* there might be nicer ways to do this .. */ delete tab; } void MainWindow::newConnection() { IRCServerList list(this, "ServerList", TRUE); if (list.exec() == QDialog::Accepted && list.hasServer()) { IRCServerTab *serverTab = new IRCServerTab(list.server(), this, m_tabWidget); addTab(serverTab); serverTab->doConnect(); } } void MainWindow::settings() { IRCSettings settings(this, "Settings", TRUE); if (settings.exec() == QDialog::Accepted) { |