-rw-r--r-- | noncore/net/opieirc/ircmisc.cpp | 16 | ||||
-rw-r--r-- | noncore/net/opieirc/ircmisc.h | 3 | ||||
-rw-r--r-- | noncore/net/opieirc/ircservereditor.cpp | 10 | ||||
-rw-r--r-- | noncore/net/opieirc/ircserverlist.cpp | 7 | ||||
-rw-r--r-- | noncore/net/opieirc/ircsettings.cpp | 11 | ||||
-rw-r--r-- | noncore/net/opieirc/mainwindow.cpp | 6 |
6 files changed, 48 insertions, 5 deletions
diff --git a/noncore/net/opieirc/ircmisc.cpp b/noncore/net/opieirc/ircmisc.cpp index 2e7f316..c8e6190 100644 --- a/noncore/net/opieirc/ircmisc.cpp +++ b/noncore/net/opieirc/ircmisc.cpp @@ -10,88 +10,104 @@ IRCColorLabel::IRCColorLabel(QColor color, QWidget *parent, const char *name, WF setFrameShadow(QFrame::Sunken); setBackgroundColor(m_color); } void IRCColorLabel::mousePressEvent(QMouseEvent *) { m_color = OColorDialog::getColor(m_color); setBackgroundColor(m_color); } QColor IRCColorLabel::color() { return m_color; } IRCFramedColorLabel::IRCFramedColorLabel(QColor color, QWidget *parent, const char *name, WFlags f) : QWidget(parent, name, f) { QVBoxLayout *layout = new QVBoxLayout(this, 10, 0); m_label = new IRCColorLabel(color, this); layout->addWidget(m_label); } QColor IRCFramedColorLabel::color() { return m_label->color(); } IRCTabBar::IRCTabBar(QWidget *parent, const char *name) : QTabBar(parent, name) { } int IRCTabBar::insertTab(QTab *tab, int index = -1) { /* 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) { ((QExtTab *)tab(index))->color = color; update(); } void IRCTabBar::paintLabel(QPainter* p, const QRect& br, QTab* t, bool focus) const { QRect r = br; 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); } 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_Tab) { + printf("got tab\n"); + return; } 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) { + qDebug("tab!"); + return TRUE; + } + } + return QLineEdit::eventFilter(object, event); +} diff --git a/noncore/net/opieirc/ircmisc.h b/noncore/net/opieirc/ircmisc.h index 7151e6b..6a8db50 100644 --- a/noncore/net/opieirc/ircmisc.h +++ b/noncore/net/opieirc/ircmisc.h @@ -14,78 +14,79 @@ 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> /* IRCFramedColorLabel is used to display a color */ class IRCColorLabel : public QLabel { Q_OBJECT public: IRCColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); QColor color(); void mousePressEvent(QMouseEvent *event); protected: QColor m_color; }; class IRCFramedColorLabel : public QWidget { Q_OBJECT public: IRCFramedColorLabel(QColor color, QWidget *parent = 0, const char *name = 0, WFlags f = 0); QColor color(); protected: IRCColorLabel *m_label; }; /* 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 */ +/* A QLineEdit with history functionality and tab completion */ class IRCHistoryLineEdit : public QLineEdit { Q_OBJECT public: IRCHistoryLineEdit(QWidget *parent = 0, const char *name = 0); + virtual bool eventFilter(QObject *object, QEvent *event); protected: void keyPressEvent(QKeyEvent *); protected: QStringList m_history; int m_index; }; #endif /* __IRCMISC_H */ diff --git a/noncore/net/opieirc/ircservereditor.cpp b/noncore/net/opieirc/ircservereditor.cpp index f976c84..8604835 100644 --- a/noncore/net/opieirc/ircservereditor.cpp +++ b/noncore/net/opieirc/ircservereditor.cpp @@ -1,77 +1,85 @@ #include <qmessagebox.h> #include <qlayout.h> #include <qlabel.h> +#include <qwhatsthis.h> #include "ircservereditor.h" -IRCServerEditor::IRCServerEditor(IRCServer server, QWidget* parent, const char* name, bool modal = FALSE, WFlags f) : QDialog(parent, name, modal, f) { +IRCServerEditor::IRCServerEditor(IRCServer server, QWidget* parent, const char* name, bool modal = FALSE, WFlags) : QDialog(parent, name, modal, WStyle_ContextHelp) { QGridLayout *layout = new QGridLayout(this, 7, 2, 5, 5); QLabel *label = new QLabel(tr("Profile name :"), this); m_name = new QLineEdit(server.name(), this); + QWhatsThis::add(m_name, tr("The name of this server profile in the overview")); layout->addWidget(label, 0, 0); layout->addWidget(m_name, 0, 1); label = new QLabel(tr("Hostname :"), this); m_hostname = new QLineEdit(server.hostname(), this); + QWhatsThis::add(m_hostname, tr("The server to connect to - can be any valid host name or IP address")); layout->addWidget(label, 1, 0); layout->addWidget(m_hostname, 1, 1); label = new QLabel(tr("Port :"), this); m_port = new QLineEdit(QString::number(server.port()), this); + QWhatsThis::add(m_port, tr("The server port to connect to. Usually 6667")); layout->addWidget(label, 2, 0); layout->addWidget(m_port, 2, 1); label = new QLabel(tr("Nickname :"), this); m_nickname = new QLineEdit(server.nick(), this); + QWhatsThis::add(m_nickname, tr("Your nick name on the IRC network")); layout->addWidget(label, 3, 0); layout->addWidget(m_nickname, 3, 1); label = new QLabel(tr("Realname :"), this); m_realname = new QLineEdit(server.realname(), this); + QWhatsThis::add(m_realname, tr("Your real name")); layout->addWidget(label, 4, 0); layout->addWidget(m_realname, 4, 1); label = new QLabel(tr("Password :"), this); m_password = new QLineEdit(server.password(), this); + QWhatsThis::add(m_password, tr("Password to connect to the server (if required)")); layout->addWidget(label, 5, 0); layout->addWidget(m_password, 5, 1); label = new QLabel(tr("Channels :"), this); m_channels = new QLineEdit(server.channels(), this); + QWhatsThis::add(m_channels, tr("Comma-Separated list of all channels you would like to join automatically")); layout->addWidget(label, 6, 0); layout->addWidget(m_channels, 6, 1); setCaption(tr("Edit server information")); showMaximized(); } void IRCServerEditor::accept() { if (m_name->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Profile name required")); else if (m_hostname->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Host name required")); else if (m_port->text().toInt()<=0) QMessageBox::critical(this, tr("Error"), tr("Port required")); else if (m_nickname->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Nickname required")); else if (m_realname->text().length()==0) QMessageBox::critical(this, tr("Error"), tr("Realname required")); else { /* Now verify whether the channel list has a valid format */ QStringList channels = QStringList::split(QChar(','), m_channels->text()); for (QStringList::Iterator it = channels.begin(); it != channels.end(); ++it) { QString channelName = (*it).stripWhiteSpace(); if (!channelName.startsWith("#") && !channelName.startsWith("+")) { QMessageBox::critical(this, tr("Error"), tr("The channel list needs to contain a\ncomma separated list of channel\n names which start with either '#' or '+'")); return; } } QDialog::accept(); } } IRCServer IRCServerEditor::getServer() { IRCServer server; server.setName(m_name->text()); server.setHostname(m_hostname->text()); server.setPort(m_port->text().toInt()); server.setNick(m_nickname->text()); server.setRealname(m_realname->text()); server.setUsername(m_nickname->text()); server.setPassword(m_password->text()); server.setChannels(m_channels->text()); return server; } diff --git a/noncore/net/opieirc/ircserverlist.cpp b/noncore/net/opieirc/ircserverlist.cpp index 3293591..595ae3e 100644 --- a/noncore/net/opieirc/ircserverlist.cpp +++ b/noncore/net/opieirc/ircserverlist.cpp @@ -1,101 +1,106 @@ #include <qlayout.h> #include <qlabel.h> #include <qhbox.h> #include <qpushbutton.h> +#include <qwhatsthis.h> #include "ircserverlist.h" #include "ircservereditor.h" class IRCListBoxServer : public QListBoxText { public: IRCListBoxServer(IRCServer server) : QListBoxText(server.name()) { m_server = server; } IRCServer server() { return m_server; } void setServer(IRCServer server) { m_server = server; setText(m_server.name()); } protected: IRCServer m_server; }; -IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFlags f) : QDialog(parent, name, modal, f) { +IRCServerList::IRCServerList(QWidget* parent, const char *name, bool modal, WFlags) : QDialog(parent, name, modal, WStyle_ContextHelp) { QVBoxLayout *layout = new QVBoxLayout(this, 5, 5); setCaption(tr("Serverlist Browser")); QLabel *label = new QLabel(tr("Please choose a server profile"), this); label->setAlignment(AlignHCenter); layout->addWidget(label); m_list = new QListBox(this); + QWhatsThis::add(m_list, tr("Select a server profile from this list and then tap on OK in the upper-right corner")); layout->addWidget(m_list); QHBox *buttons = new QHBox(this); QPushButton *del = new QPushButton(tr("Delete"), buttons); QPushButton *edit = new QPushButton(tr("Edit"), buttons); QPushButton *add = new QPushButton(tr("Add"), buttons); + QWhatsThis::add(del, tr("Delete the currently selected server profile")); + QWhatsThis::add(edit, tr("Edit the currently selected server profile")); + QWhatsThis::add(add, tr("Add a new server profile")); connect(del, SIGNAL(clicked()), this, SLOT(delServer())); connect(edit, SIGNAL(clicked()), this, SLOT(editServer())); connect(add, SIGNAL(clicked()), this, SLOT(addServer())); layout->addWidget(buttons); /* Load the configuration file */ m_config = new Config("OpieIRC"); m_config->setGroup("OpieIRC"); int count = m_config->readNumEntry("ServerCount", 0); if (count) { for (int i=0; i<count; i++) { m_config->setGroup("OpieIRC"); QString name = m_config->readEntry("Server"+QString::number(i)); if (name.length() > 0) { IRCServer server; m_config->setGroup(name); server.setName(name); server.setHostname(m_config->readEntry("Hostname")); server.setPort(m_config->readNumEntry("Port")); server.setUsername(m_config->readEntry("Username")); server.setPassword(m_config->readEntry("Password")); server.setNick(m_config->readEntry("Nick")); server.setRealname(m_config->readEntry("Realname")); server.setChannels(m_config->readEntry("Channels")); m_list->insertItem(new IRCListBoxServer(server)); } } } showMaximized(); } void IRCServerList::addServer() { IRCServer server; IRCServerEditor editor(server, this, "ServerEditor", TRUE); if (editor.exec() == QDialog::Accepted) { server = editor.getServer(); /* Gets deleted by QListBox, so this is ok */ m_list->insertItem(new IRCListBoxServer(server)); } } void IRCServerList::delServer() { int index = m_list->currentItem(); if (index != -1) { m_list->removeItem(index); } } void IRCServerList::editServer() { int index = m_list->currentItem(); if (index != -1) { IRCListBoxServer *item = (IRCListBoxServer *)m_list->item(index); IRCServer server = item->server(); IRCServerEditor editor(server, this, "ServerEditor", TRUE); if (editor.exec() == QDialog::Accepted) { server = editor.getServer(); item->setServer(server); } } } int IRCServerList::exec() { int returncode = QDialog::exec(); /* Now save the changes */ diff --git a/noncore/net/opieirc/ircsettings.cpp b/noncore/net/opieirc/ircsettings.cpp index 1903e87..78eaed3 100644 --- a/noncore/net/opieirc/ircsettings.cpp +++ b/noncore/net/opieirc/ircsettings.cpp @@ -1,95 +1,104 @@ #include <qlayout.h> #include <qvalidator.h> #include <qscrollview.h> +#include <qwhatsthis.h> #include "ircsettings.h" #include "irctab.h" #include "ircmisc.h" -IRCSettings::IRCSettings(QWidget* parent, const char* name, bool modal, WFlags f) : QDialog(parent, name, modal, f) { +IRCSettings::IRCSettings(QWidget* parent, const char* name, bool modal, WFlags) : QDialog(parent, name, modal, WStyle_ContextHelp) { setCaption("Settings"); m_config = new Config("OpieIRC"); m_config->setGroup("OpieIRC"); QHBoxLayout *l = new QHBoxLayout(this, 2, 2); QTabWidget *tw = new QTabWidget(this); l->addWidget(tw); /* General Configuration */ QWidget *widget = new QWidget(tw); QGridLayout *layout = new QGridLayout(widget, 1, 2, 5, 0); QLabel *label = new QLabel(tr("Lines displayed :"), widget); layout->addWidget(label, 0, 0); m_lines = new QLineEdit(m_config->readEntry("Lines", "100"), widget); + QWhatsThis::add(m_lines, tr("Amount of lines to be displayed in chats before old lines get deleted - this is necessary to restrain memory consumption. Set to 0 if you don't need this")); QIntValidator *validator = new QIntValidator(this); validator->setTop(10000); validator->setBottom(0); m_lines->setValidator(validator); layout->addWidget(m_lines, 0, 1); tw->addTab(widget, tr("General")); /* Color configuration */ QScrollView *view = new QScrollView(tw); view->setResizePolicy(QScrollView::AutoOneFit); widget = new QWidget(view->viewport()); view->addChild(widget); layout = new QGridLayout(widget, 7, 2, 5, 0); label = new QLabel(tr("Background color :"), widget); layout->addWidget(label, 0, 0); m_background = new IRCFramedColorLabel(QColor(m_config->readEntry("BackgroundColor", "#FFFFFF")), widget); + QWhatsThis::add(m_background, tr("Background color to be used in chats")); layout->addWidget(m_background, 0, 1); label = new QLabel(tr("Normal text color :"), widget); layout->addWidget(label, 1, 0); m_text = new IRCFramedColorLabel(m_config->readEntry("TextColor", "#000000"), widget); + QWhatsThis::add(m_text, tr("Text color to be used in chats")); layout->addWidget(m_text, 1, 1); label = new QLabel(tr("Error color :"), widget); layout->addWidget(label, 2, 0); m_error = new IRCFramedColorLabel(m_config->readEntry("ErrorColor", "#FF0000"), widget); + QWhatsThis::add(m_error, tr("Text color to be used to display errors")); layout->addWidget(m_error, 2, 1); label = new QLabel(tr("Text written by yourself :"), widget); layout->addWidget(label, 3, 0); m_self = new IRCFramedColorLabel(m_config->readEntry("SelfColor", "#CC0000"), widget); + QWhatsThis::add(m_self, tr("Text color to be used to identify text written by yourself")); layout->addWidget(m_self, 3, 1); label = new QLabel(tr("Text written by others :"), widget); layout->addWidget(label, 4, 0); m_other = new IRCFramedColorLabel(m_config->readEntry("OtherColor", "#0000BB"), widget); + 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 IRCFramedColorLabel(m_config->readEntry("ServerColor", "#0000FF"), widget); + 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 IRCFramedColorLabel(m_config->readEntry("NotificationColor", "#AAE300"), widget); + QWhatsThis::add(m_notification, tr("Text color to be used to display notifications")); layout->addWidget(m_notification, 6, 1); tw->addTab(view, tr("Colors")); showMaximized(); } QString IRCSettings::getColorString(QWidget *widget) { QColor color = ((IRCFramedColorLabel *)widget)->color(); QString temp; temp.sprintf("#%02x%02x%02x", color.red(), color.green(), color.blue()); return temp; } void IRCSettings::accept() { IRCTab::m_backgroundColor = getColorString(m_background); IRCTab::m_textColor = getColorString(m_text); IRCTab::m_errorColor = getColorString(m_error); IRCTab::m_selfColor = getColorString(m_self); IRCTab::m_otherColor = getColorString(m_other); IRCTab::m_serverColor = getColorString(m_server); IRCTab::m_notificationColor = getColorString(m_notification); IRCTab::m_maxLines = m_lines->text().toInt(); m_config->writeEntry("BackgroundColor", getColorString(m_background)); m_config->writeEntry("TextColor", getColorString(m_text)); m_config->writeEntry("ErrorColor", getColorString(m_error)); m_config->writeEntry("SelfColor", getColorString(m_self)); m_config->writeEntry("OtherColor", getColorString(m_other)); m_config->writeEntry("ServerColor", getColorString(m_server)); m_config->writeEntry("NotificationColor", getColorString(m_notification)); m_config->writeEntry("Lines", m_lines->text()); QDialog::accept(); } IRCSettings::~IRCSettings() { delete m_config; } diff --git a/noncore/net/opieirc/mainwindow.cpp b/noncore/net/opieirc/mainwindow.cpp index bb03a1c..7928310 100644 --- a/noncore/net/opieirc/mainwindow.cpp +++ b/noncore/net/opieirc/mainwindow.cpp @@ -1,84 +1,88 @@ #include <qpe/qpemenubar.h> #include <qpe/resource.h> #include <qpe/config.h> #include <qpopupmenu.h> +#include <qwhatsthis.h> #include "mainwindow.h" #include "ircservertab.h" #include "ircserverlist.h" #include "ircsettings.h" -MainWindow::MainWindow(QWidget *parent, const char *name, WFlags f) : QMainWindow(parent, name, f) { +MainWindow::MainWindow(QWidget *parent, const char *name, WFlags) : QMainWindow(parent, name, WStyle_ContextHelp) { setCaption(tr("IRC Client")); m_tabWidget = new IRCTabWidget(this); + QWhatsThis::add(m_tabWidget, tr("Server connections, channels, queries and other things will be placed here")); connect(m_tabWidget, SIGNAL(currentChanged(QWidget *)), this, SLOT(selected(QWidget *))); setCentralWidget(m_tabWidget); setToolBarsMovable(FALSE); QPEMenuBar *menuBar = new QPEMenuBar(this); QPopupMenu *irc = new QPopupMenu(this); menuBar->insertItem(tr("IRC"), irc); QAction *a = new QAction(tr("New connection"), Resource::loadPixmap("pass"), QString::null, 0, this, 0); connect(a, SIGNAL(activated()), this, SLOT(newConnection())); + a->setWhatsThis(tr("Create a new connection to an IRC server")); a->addTo(irc); a = new QAction(tr("Settings"), Resource::loadPixmap("SettingsIcon"), QString::null, 0, this, 0); + a->setWhatsThis(tr("Configure OpieIRC's behavior and appearance")); connect(a, SIGNAL(activated()), this, SLOT(settings())); a->addTo(irc); loadSettings(); } void MainWindow::loadSettings() { Config config("OpieIRC"); config.setGroup("OpieIRC"); IRCTab::m_backgroundColor = config.readEntry("BackgroundColor", "#FFFFFF"); IRCTab::m_textColor = config.readEntry("TextColor", "#000000"); IRCTab::m_errorColor = config.readEntry("ErrorColor", "#FF0000"); IRCTab::m_selfColor = config.readEntry("SelfColor", "#CC0000"); IRCTab::m_otherColor = config.readEntry("OtherColor", "#0000BB"); IRCTab::m_serverColor = config.readEntry("ServerColor", "#0000FF"); IRCTab::m_notificationColor = config.readEntry("NotificationColor", "#AA3300"); IRCTab::m_maxLines = config.readNumEntry("Lines", 100); } void MainWindow::selected(QWidget *) { m_tabWidget->setTabColor(m_tabWidget->currentPageIndex(), black); } void MainWindow::addTab(IRCTab *tab) { connect(tab, SIGNAL(changed(IRCTab *)), this, SLOT(changeEvent(IRCTab *))); 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) { QListIterator<IRCTab> it(m_tabs); for (; it.current(); ++it) { /* Inform all tabs about the new settings */ it.current()->settingsChanged(); } } } |