diff options
| author | 2010-01-10 15:15:40 +0000 | |
|---|---|---|
| committer | 2010-01-10 15:15:40 +0000 | |
| commit | ba37ea023c8aac9b15af4fb4068843f6ebe3d02b (patch) | |
| tree | 34c99cfb289581a47928302204fc15b8fe67f34a | |
| parent | disable buffer size in logviewer (see #524) (diff) | |
| download | KVIrc-ba37ea023c8aac9b15af4fb4068843f6ebe3d02b.tar.gz KVIrc-ba37ea023c8aac9b15af4fb4068843f6ebe3d02b.tar.bz2 KVIrc-ba37ea023c8aac9b15af4fb4068843f6ebe3d02b.zip | |
added themedlineedit, used in mode widget
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3826 17fca916-40b9-46aa-a4ea-0a15b648b75c
| -rw-r--r-- | src/kvirc/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_modew.cpp | 93 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_modew.h | 18 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_themedlabel.cpp | 12 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_themedlabel.h | 2 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_themedlineedit.cpp | 122 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_themedlineedit.h | 46 |
7 files changed, 205 insertions, 90 deletions
diff --git a/src/kvirc/CMakeLists.txt b/src/kvirc/CMakeLists.txt index 4023cbe83..29d6b6085 100644 --- a/src/kvirc/CMakeLists.txt +++ b/src/kvirc/CMakeLists.txt @@ -53,6 +53,7 @@ SET(kvirc_MOC_HDRS ui/kvi_statusbarapplet.h ui/kvi_texticonwin.h ui/kvi_themedlabel.h + ui/kvi_themedlineedit.h ui/kvi_toolbar.h ui/kvi_toolwindows_container.h ui/kvi_topicw.h @@ -134,6 +135,7 @@ SET(kvirc_SRCS ui/kvi_statusbarapplet.cpp ui/kvi_texticonwin.cpp ui/kvi_themedlabel.cpp + ui/kvi_themedlineedit.cpp ui/kvi_toolbar.cpp ui/kvi_toolwindows_container.cpp ui/kvi_topicw.cpp diff --git a/src/kvirc/ui/kvi_modew.cpp b/src/kvirc/ui/kvi_modew.cpp index 29f1adfaf..00a34da12 100644 --- a/src/kvirc/ui/kvi_modew.cpp +++ b/src/kvirc/ui/kvi_modew.cpp @@ -22,28 +22,21 @@ // //============================================================================ - -#include "kvi_themedlabel.h" #include "kvi_channel.h" #include "kvi_options.h" #include "kvi_ircconnectionserverinfo.h" #include "kvi_ircconnectionuserinfo.h" #include "kvi_tal_hbox.h" -#include <QFrame> -#include <QLineEdit> #include <QEvent> #include <QResizeEvent> #include <QByteArray> KviModeWidget::KviModeWidget(QWidget * par,KviChannel* chan,const char * name) -:QFrame(par) +:KviThemedLineEdit(par, name) { - setObjectName(name); m_pChannel=chan; - m_pLabel=0; - m_pLineEdit=0; - setAutoFillBackground(false); + connect(this,SIGNAL(textEdited ( const QString & ) ),this,SLOT(editorTextEdited( const QString & ))); reset(); } @@ -53,19 +46,12 @@ KviModeWidget::~KviModeWidget() void KviModeWidget::reset() { - if(m_pLineEdit) - { - delete m_pLineEdit; - m_pLineEdit=0; - } - if(!m_pLabel) - m_pLabel=new KviThemedLabel(this,0); + setText(m_pChannel->channelMode()); + setReadOnly(true); + refreshModes(); - m_pLabel->show(); - connect(m_pLabel,SIGNAL(doubleClicked()),this,SLOT(labelDoubleClick())); - QResizeEvent* ev=new QResizeEvent(size(),size()); - resizeEvent(ev); - delete ev; + + if(m_pChannel->input()) m_pChannel->setFocus(); } @@ -76,61 +62,43 @@ void KviModeWidget::refreshModes() szMode+=QString(" k:%1").arg(m_pChannel->channelKey()); if(!m_pChannel->channelLimit().isEmpty()) szMode+=QString(" l:%1").arg(m_pChannel->channelLimit().toUtf8().data()); - if(m_pLabel) - m_pLabel->setText(szMode); -} - -void KviModeWidget::applyOptions() -{ - if(m_pLabel) m_pLabel->applyOptions(); -} - -void KviModeWidget::resizeEvent(QResizeEvent *e) -{ - if(e)QFrame::resizeEvent(e); - if(m_pLabel) m_pLabel->setGeometry(0,0,width(),height()); - if(m_pLineEdit) m_pLineEdit->setGeometry(0,0,width(),height()); + setText(szMode); } -void KviModeWidget::labelDoubleClick() +void KviModeWidget::mouseDoubleClickEvent(QMouseEvent *) { - if(m_pLabel && ( m_pChannel->isMeHalfOp() || m_pChannel->isMeOp() || m_pChannel->isMeChanOwner() || m_pChannel->isMeChanAdmin() || m_pChannel->connection()->userInfo()->hasUserMode('o') || m_pChannel->connection()->userInfo()->hasUserMode('O')) ) + if(m_pChannel->isMeHalfOp() || + m_pChannel->isMeOp() || + m_pChannel->isMeChanOwner() || + m_pChannel->isMeChanAdmin() || + m_pChannel->connection()->userInfo()->hasUserMode('o') || + m_pChannel->connection()->userInfo()->hasUserMode('O')) { - delete m_pLabel; - m_pLabel=0; - m_pLineEdit = new QLineEdit(this); - m_pLineEdit->setText(m_pChannel->channelMode()); - m_pLineEdit->show(); - m_pLineEdit->setFocus(); - resizeEvent(new QResizeEvent(size(),size())); - m_pLineEdit->installEventFilter( this ); - connect(m_pLineEdit,SIGNAL(textChanged ( const QString & ) ),this,SLOT(editorTextChanged( const QString & ))); + setReadOnly(false); } } -bool KviModeWidget::eventFilter( QObject *obj, QEvent *ev ) +void KviModeWidget::keyReleaseEvent (QKeyEvent * e) { - if( (obj==m_pLineEdit) && ( ev->type() == QEvent::KeyPress ) ) + switch(e->key()) { - QKeyEvent *keyEvent = (QKeyEvent*)ev; - switch(keyEvent->key()) - { - case Qt::Key_Return: - case Qt::Key_Enter: - editorReturnPressed(); - return TRUE; - case Qt::Key_Escape: - reset(); - return TRUE; - } + case Qt::Key_Return: + case Qt::Key_Enter: + editorReturnPressed(); + break; + case Qt::Key_Escape: + reset(); + break; + default: + KviThemedLineEdit::keyReleaseEvent(e); + break; } - return QFrame::eventFilter( obj, ev ); } void KviModeWidget::editorReturnPressed() { QString szCurModes=m_pChannel->channelMode(); - QString szNewModes=m_pLineEdit->text(); + QString szNewModes=text(); QString szMinusModes; for(int i=0; i<szCurModes.length(); i++) { @@ -150,7 +118,7 @@ void KviModeWidget::editorReturnPressed() reset(); } -void KviModeWidget::editorTextChanged( const QString & text) +void KviModeWidget::editorTextEdited(const QString & text) { int i = 0; QString szText=text; @@ -160,7 +128,6 @@ void KviModeWidget::editorTextChanged( const QString & text) szText.indexOf(szText[i])<i,Qt::CaseInsensitive ) szText.remove(i,1); } - m_pLineEdit->setText(szText); } #ifndef COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/kvirc/ui/kvi_modew.h b/src/kvirc/ui/kvi_modew.h index 5c4495189..95efdbf2c 100644 --- a/src/kvirc/ui/kvi_modew.h +++ b/src/kvirc/ui/kvi_modew.h @@ -25,15 +25,11 @@ // //============================================================================ -#include "kvi_themedlabel.h" -#include "kvi_tal_hbox.h" - -#include <QFrame> -#include <QLineEdit> +#include "kvi_themedlineedit.h" class KviChannel; -class KVIRC_API KviModeWidget : public QFrame +class KVIRC_API KviModeWidget : public KviThemedLineEdit { Q_OBJECT @@ -42,18 +38,14 @@ public: ~KviModeWidget(); void reset(); void refreshModes(); - void applyOptions(); private: KviChannel * m_pChannel; - KviThemedLabel * m_pLabel; - QLineEdit * m_pLineEdit; protected: - void resizeEvent(QResizeEvent *e); - bool eventFilter( QObject *obj, QEvent *ev ); + void mouseDoubleClickEvent(QMouseEvent * e); + void keyReleaseEvent (QKeyEvent * e); public slots: - void labelDoubleClick(); void editorReturnPressed(); - void editorTextChanged( const QString & ); + void editorTextEdited( const QString & ); }; #endif //_KVI_MODEW_H_ diff --git a/src/kvirc/ui/kvi_themedlabel.cpp b/src/kvirc/ui/kvi_themedlabel.cpp index b17ed8275..52bab1b25 100644 --- a/src/kvirc/ui/kvi_themedlabel.cpp +++ b/src/kvirc/ui/kvi_themedlabel.cpp @@ -47,14 +47,6 @@ KviThemedLabel::~KviThemedLabel() { } -/*QSize KviThemedLabel::sizeHint() -{ - QSize size=QFrame::sizeHint(); - int iHeight=fontMetrics().height()*QStringList::split('\n',m_szText).count()+4; - size.setHeight(iHeight); - return size; -}*/ - void KviThemedLabel::setText(const char * text) { m_szText = QString(text); @@ -62,7 +54,6 @@ void KviThemedLabel::setText(const char * text) { int iHeight=fontMetrics().height()*m_szText.split('\n',QString::SkipEmptyParts).count()+4; setMinimumHeight(iHeight); - //g_pApp->postEvent(parent(),new QEvent(QEvent::Resize)); } update(); } @@ -74,7 +65,6 @@ void KviThemedLabel::setText(const QString& text) { int iHeight=fontMetrics().height()*m_szText.split('\n',QString::SkipEmptyParts).count()+4; setMinimumHeight(iHeight); - //g_pApp->postEvent(parent(),new QEvent(QEvent::Resize)); } update(); } @@ -87,9 +77,7 @@ void KviThemedLabel::applyOptions() void KviThemedLabel::paintEvent ( QPaintEvent * event ) { - QFrame::paintEvent(event); QPainter p(this); - SET_ANTI_ALIASING(p); #ifdef COMPILE_PSEUDO_TRANSPARENCY if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) { diff --git a/src/kvirc/ui/kvi_themedlabel.h b/src/kvirc/ui/kvi_themedlabel.h index 6ec93bba4..3a2996823 100644 --- a/src/kvirc/ui/kvi_themedlabel.h +++ b/src/kvirc/ui/kvi_themedlabel.h @@ -49,8 +49,6 @@ public: QString text() { return m_szText; }; void setAutoHeight(bool value) { m_bAutoHeight=value; }; void applyOptions(); - -// QSize sizeHint(); signals: void doubleClicked(); }; diff --git a/src/kvirc/ui/kvi_themedlineedit.cpp b/src/kvirc/ui/kvi_themedlineedit.cpp new file mode 100644 index 000000000..aac1dcb3a --- /dev/null +++ b/src/kvirc/ui/kvi_themedlineedit.cpp @@ -0,0 +1,122 @@ +//============================================================================= +// +// File : kvi_themedlineedit.cpp +// Creation date : Sun Jan 10 2010 12:17:00 by Fabio Bas +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2010 Fabio Bas (ctrlaltca at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// 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 program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "kvi_themedlineedit.h" +#include "kvi_options.h" +#include "kvi_settings.h" +#include "kvi_app.h" +#include "kvi_window.h" + +#include <QPainter> +#include <QStyleOptionFrameV2> + +#ifdef COMPILE_PSEUDO_TRANSPARENCY + extern QPixmap * g_pShadedChildGlobalDesktopBackground; +#endif + +KviThemedLineEdit::KviThemedLineEdit(QWidget * par,const char * name) +: QLineEdit(par) +{ + setObjectName(name); + setAutoFillBackground(false); + + QPalette pal = palette(); + pal.setBrush(QPalette::Active, QPalette::Base, Qt::transparent); + pal.setBrush(QPalette::Inactive, QPalette::Base, Qt::transparent); + pal.setBrush(QPalette::Disabled, QPalette::Base, Qt::transparent); + + setPalette(pal); + + applyOptions(); +} + +KviThemedLineEdit::~KviThemedLineEdit() +{ +} + +void KviThemedLineEdit::applyOptions() +{ + setFont(KVI_OPTION_FONT(KviOption_fontLabel)); + update(); +} + +void KviThemedLineEdit::paintEvent ( QPaintEvent * event ) +{ + QPainter p(this); + QRect r = rect(); + QPalette pal = palette(); + QStyleOptionFrameV2 option; + + option.initFrom(this); + option.rect = contentsRect(); + option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this); + option.midLineWidth = 0; + option.state |= QStyle::State_Sunken; + if(isReadOnly()) + option.state |= QStyle::State_ReadOnly; + if (QStyleOptionFrameV2 *optionV2 = qstyleoption_cast<QStyleOptionFrameV2 *>(&option)) + optionV2->features = QStyleOptionFrameV2::None; + + r = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); + int left, right, top, bottom; + getTextMargins(&left, &top, &right, &bottom); + r.setX(r.x() + left); + r.setY(r.y() + top); + r.setRight(r.right() - right); + r.setBottom(r.bottom() - bottom); + p.setClipRect(r); + +#ifdef COMPILE_PSEUDO_TRANSPARENCY + if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) + { + p.save(); + p.setCompositionMode(QPainter::CompositionMode_Source); + QColor col=KVI_OPTION_COLOR(KviOption_colorGlobalTransparencyFade); + col.setAlphaF((float)((float)KVI_OPTION_UINT(KviOption_uintGlobalTransparencyChildFadeFactor) / (float)100)); + p.fillRect(contentsRect(), col); + p.restore(); + } else if(g_pShadedChildGlobalDesktopBackground) + { + QPoint pnt = mapToGlobal(contentsRect().topLeft()); + p.drawTiledPixmap(contentsRect(),*g_pShadedChildGlobalDesktopBackground,pnt); + } else { +#endif + + if(KVI_OPTION_PIXMAP(KviOption_pixmapLabelBackground).pixmap()) + { + p.drawTiledPixmap(contentsRect(),*(KVI_OPTION_PIXMAP(KviOption_pixmapLabelBackground).pixmap())); + } else { + p.fillRect(contentsRect(),KVI_OPTION_COLOR(KviOption_colorLabelBackground)); + } + +#ifdef COMPILE_PSEUDO_TRANSPARENCY + } +#endif + + QLineEdit::paintEvent(event); +} + +#ifndef COMPILE_USE_STANDALONE_MOC_SOURCES +#include "kvi_themedlabel.moc" +#endif //!COMPILE_USE_STANDALONE_MOC_SOURCES diff --git a/src/kvirc/ui/kvi_themedlineedit.h b/src/kvirc/ui/kvi_themedlineedit.h new file mode 100644 index 000000000..530a861b8 --- /dev/null +++ b/src/kvirc/ui/kvi_themedlineedit.h @@ -0,0 +1,46 @@ +#ifndef _KVI_THEMEDLINEEDIT_H_ +#define _KVI_THEMEDLINEEDIT_H_ +//============================================================================= +// +// File : kvi_themedlineedit.h +// Creation date : Sun Jan 10 2010 12:17:00 by Fabio Bas +// +// This file is part of the KVirc irc client distribution +// Copyright (C) 2010 Fabio Bas (ctrlaltca at gmail dot com) +// +// This program is FREE software. You can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your opinion) any later version. +// +// This program is distributed in the HOPE that it will be USEFUL, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// 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 program. If not, write to the Free Software Foundation, +// Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +// +//============================================================================= + +#include "kvi_settings.h" +#include "kvi_string.h" + +#include <QLineEdit> + +class KVIRC_API KviThemedLineEdit : public QLineEdit +{ + Q_OBJECT + Q_PROPERTY(int TransparencyCapable READ dummyRead) +public: + KviThemedLineEdit(QWidget * par,const char * name); + ~KviThemedLineEdit(); +protected: + virtual void paintEvent ( QPaintEvent * event ); +public: + int dummyRead() const { return 0; }; + void applyOptions(); +}; + +#endif //_KVI_THEMEDLINEEDIT_H_ |
