diff options
| author | 2010-01-19 15:59:55 +0000 | |
|---|---|---|
| committer | 2010-01-19 15:59:55 +0000 | |
| commit | b92e241158a78399c1347f400466f92ea5557a81 (patch) | |
| tree | ed5f34a362486be63dbdcacae4d82f3e7da8be69 /src | |
| parent | Some other fixes in object module (diff) | |
| download | KVIrc-b92e241158a78399c1347f400466f92ea5557a81.tar.gz KVIrc-b92e241158a78399c1347f400466f92ea5557a81.tar.bz2 KVIrc-b92e241158a78399c1347f400466f92ea5557a81.zip | |
More stylish: inputbar+topic widget
git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3850 17fca916-40b9-46aa-a4ea-0a15b648b75c
Diffstat (limited to 'src')
| -rw-r--r-- | src/kvirc/sparser/kvi_sp_literal.cpp | 2 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_channel.cpp | 1 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_console.cpp | 1 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_input_editor.cpp | 197 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_input_editor.h | 24 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_query.cpp | 1 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_themedlabel.cpp | 48 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_themedlabel.h | 11 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_topicw.cpp | 116 | ||||
| -rw-r--r-- | src/kvirc/ui/kvi_topicw.h | 11 | ||||
| -rw-r--r-- | src/modules/dcc/canvas.cpp | 1 | ||||
| -rw-r--r-- | src/modules/dcc/chat.cpp | 1 |
12 files changed, 182 insertions, 232 deletions
diff --git a/src/kvirc/sparser/kvi_sp_literal.cpp b/src/kvirc/sparser/kvi_sp_literal.cpp index 7a0af6dc4..10b5c3900 100644 --- a/src/kvirc/sparser/kvi_sp_literal.cpp +++ b/src/kvirc/sparser/kvi_sp_literal.cpp @@ -1653,7 +1653,7 @@ void KviServerParser::parseUserMode(KviIrcMessage *msg,const char * modeflptr) void KviServerParser::parseLiteralMode(KviIrcMessage *msg) { - // NICK + // MODE // :source MODE target <params> // :source MODE <me> +|-modeflag // :source MODE <channel> +-modeflags [parameters] diff --git a/src/kvirc/ui/kvi_channel.cpp b/src/kvirc/ui/kvi_channel.cpp index e31934576..d9e692d2b 100644 --- a/src/kvirc/ui/kvi_channel.cpp +++ b/src/kvirc/ui/kvi_channel.cpp @@ -36,7 +36,6 @@ #include "kvi_windowlist.h" #include "kvi_frame.h" #include "kvi_config.h" -#include "kvi_themedlabel.h" #include "kvi_maskeditor.h" #include "kvi_mirccntrl.h" #include "kvi_settings.h" diff --git a/src/kvirc/ui/kvi_console.cpp b/src/kvirc/ui/kvi_console.cpp index 28d64324e..5c7d0bd2f 100644 --- a/src/kvirc/ui/kvi_console.cpp +++ b/src/kvirc/ui/kvi_console.cpp @@ -52,7 +52,6 @@ #include "kvi_irctoolbar.h" #include "kvi_internalcmd.h" #include "kvi_sparser.h" -#include "kvi_themedlabel.h" #include "kvi_modulemanager.h" #include "kvi_fileutils.h" #include "kvi_time.h" diff --git a/src/kvirc/ui/kvi_input_editor.cpp b/src/kvirc/ui/kvi_input_editor.cpp index d1ba21da8..fd42e5126 100644 --- a/src/kvirc/ui/kvi_input_editor.cpp +++ b/src/kvirc/ui/kvi_input_editor.cpp @@ -70,12 +70,12 @@ extern KviColorWindow * g_pColorWindow; int KviInputEditor::g_iInputInstances = 0; int KviInputEditor::g_iInputFontCharWidth[256]; QFontMetrics * KviInputEditor::g_pLastFontMetrics = 0; - + KviInputEditor::KviInputEditor(QWidget * pPar, KviWindow * pWnd, KviUserListView * pView) -:QFrame(pPar) +:QWidget(pPar) { ++KviInputEditor::g_iInputInstances; - setObjectName("input_frame"); + setObjectName("input_widget"); m_pIconMenu = 0; m_pInputParent = pPar; m_iMaxBufferSize = KVI_INPUT_MAX_BUFFER_SIZE; @@ -93,7 +93,7 @@ KviInputEditor::KviInputEditor(QWidget * pPar, KviWindow * pWnd, KviUserListView m_bCursorOn = false; //Cursor state m_iCursorTimer = 0; //Timer that iverts the cursor state m_iDragTimer = 0; //Timer for drag selection updates - m_iLastCursorXPosition = KVI_INPUT_MARGIN; //Calculated in paintEvent + m_iLastCursorXPosition = 0; //Calculated in paintEvent m_iSelectionAnchorChar = -1; //Character clicked at the beginning of the selection process m_iCurHistoryIdx = -1; //No data in the history m_bUpdatesEnabled = true; @@ -108,16 +108,22 @@ KviInputEditor::KviInputEditor(QWidget * pPar, KviWindow * pWnd, KviUserListView setAttribute(Qt::WA_InputMethodEnabled, true); 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); + setFocusPolicy(Qt::StrongFocus); setAcceptDrops(true); - setFrameStyle( StyledPanel ); - setFrameShadow( Plain ); m_pIconMenu = new KviTalPopupMenu(); connect(m_pIconMenu,SIGNAL(activated(int)),this,SLOT(iconPopupActivated(int))); setCursor(Qt::IBeamCursor); + setContentsMargins(KVI_INPUT_MARGIN,KVI_INPUT_MARGIN,KVI_INPUT_MARGIN,KVI_INPUT_MARGIN); //set the font and font metrics applyOptions(); } @@ -202,71 +208,109 @@ int KviInputEditor::heightHint() const QSize KviInputEditor::sizeHint() const { - //grabbed from qlineedit.cpp ensurePolished(); QFontMetrics *fm = KviInputEditor::getLastFontMetrics(font()); - return QSize(fm->width( 'x' ) * 17 + lineWidth() + midLineWidth(), // "some" - fm->height() + 8 + lineWidth() + midLineWidth()); // innerMargin 2px * 2 + int h = qMax(fm->height(), 14) + 2*(KVI_INPUT_MARGIN + KVI_INPUT_PADDING + KVI_INPUT_XTRAPADDING); + int w = fm->width(QLatin1Char('x')) * 17 + 2*(KVI_INPUT_MARGIN + KVI_INPUT_PADDING + KVI_INPUT_XTRAPADDING); + QStyleOptionFrameV2 option; + option.initFrom(this); + option.rect = rect(); + option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this); + option.midLineWidth = 0; + + option.state |= QStyle::State_Sunken; + if(isReadOnly()) + option.state |= QStyle::State_ReadOnly; + option.features = QStyleOptionFrameV2::None; + + return (style()->sizeFromContents(QStyle::CT_LineEdit, &option, QSize(w, h). + expandedTo(QApplication::globalStrut()), this)); } void KviInputEditor::paintEvent(QPaintEvent *) { QPainter p(this); - SET_ANTI_ALIASING(p); - drawContents(&p); -} - -void KviInputEditor::drawContents(QPainter * p) -{ - if(!isVisible())return; + QStyleOptionFrameV2 option; - QRect rect = contentsRect(); - int iWidgetWidth = rect.width(); - int iWidgetHeight = rect.height(); + option.initFrom(this); + option.rect = rect(); + option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this); + option.midLineWidth = 0; + + option.state |= QStyle::State_Sunken; + if(isReadOnly()) + option.state |= QStyle::State_ReadOnly; + option.features = QStyleOptionFrameV2::None; - QFontMetrics * fm = KviInputEditor::getLastFontMetrics(font()); + QRect r = style()->subElementRect(QStyle::SE_LineEditContents, &option, this); + r.setX(r.x() + KVI_INPUT_MARGIN); + r.setY(r.y() + KVI_INPUT_MARGIN); + r.setRight(r.right() - KVI_INPUT_MARGIN); + r.setBottom(r.bottom() - KVI_INPUT_MARGIN-1); + p.setClipRect(r); #ifdef COMPILE_PSEUDO_TRANSPARENCY if(KVI_OPTION_BOOL(KviOption_boolUseCompositingForTransparency) && g_pApp->supportsCompositing()) { - p->save(); - p->setCompositionMode(QPainter::CompositionMode_Source); + 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(rect, col); - p->restore(); + p.fillRect(r, col); + p.restore(); } else if(g_pShadedChildGlobalDesktopBackground) { - QPoint pnt = mapToGlobal(rect.topLeft()); - p->drawTiledPixmap(1,1,iWidgetWidth,iWidgetHeight,*g_pShadedChildGlobalDesktopBackground,pnt.x(),pnt.y()); + QPoint pnt = mapToGlobal(contentsRect().topLeft()); + p.drawTiledPixmap(r,*g_pShadedChildGlobalDesktopBackground,pnt); } else { #endif - QPixmap * pPix = KVI_OPTION_PIXMAP(KviOption_pixmapInputBackground).pixmap(); + if(KVI_OPTION_PIXMAP(KviOption_pixmapLabelBackground).pixmap()) + { + p.drawTiledPixmap(r,*(KVI_OPTION_PIXMAP(KviOption_pixmapLabelBackground).pixmap())); + } else { + p.fillRect(r,KVI_OPTION_COLOR(KviOption_colorLabelBackground)); + } - p->fillRect(1,1,iWidgetWidth,iWidgetHeight,KVI_OPTION_COLOR(KviOption_colorInputBackground)); - if(pPix) - KviPixmapUtils::drawPixmapWithPainter(p,pPix,KVI_OPTION_UINT(KviOption_uintInputPixmapAlign),rect,iWidgetWidth,iWidgetHeight); #ifdef COMPILE_PSEUDO_TRANSPARENCY } #endif - int iCurXPos = KVI_INPUT_MARGIN; - int iMaxXPos = iWidgetWidth-2*KVI_INPUT_MARGIN; + r.setX(r.x() + KVI_INPUT_PADDING); + r.setY(r.y() + KVI_INPUT_PADDING); + r.setRight(r.right() - KVI_INPUT_PADDING); + r.setBottom(r.bottom() - KVI_INPUT_PADDING); + p.setClipRect(r); + + p.save(); + p.translate(r.topLeft()); + drawContents(&p); + p.restore(); + + p.setClipRect(rect()); + style()->drawPrimitive(QStyle::PE_PanelLineEdit, &option, &p, this); +} + +void KviInputEditor::drawContents(QPainter * p) +{ + QRect rect = p->clipRegion().boundingRect(); + QFontMetrics * fm = KviInputEditor::getLastFontMetrics(font()); + + int iCurXPos = 0; + int iMaxXPos = rect.width()-1; m_iCurBack = KVI_INPUT_DEF_BACK; //transparent m_iCurFore = KVI_INPUT_DEF_FORE; //normal fore color m_bCurBold = false; m_bCurUnderline = false; - int iTop = 2; - int iBottom = iWidgetHeight - 2; - int iTextBaseline = iWidgetHeight - fm->descent() - 2; //2 = bottom margin + int iTop = KVI_INPUT_XTRAPADDING; + int iBottom = rect.height() - KVI_INPUT_XTRAPADDING; + + int iTextBaseline = iBottom - fm->descent(); runUpToTheFirstVisibleChar(); int iCharIdx = m_iFirstVisibleChar; - p->setClipRect(1,1,iWidgetWidth,iWidgetHeight); - //Control the selection state if((m_iSelectionEnd < m_iSelectionBegin) || (m_iSelectionEnd == -1) || (m_iSelectionBegin == -1)) { @@ -278,13 +322,12 @@ void KviInputEditor::drawContents(QPainter * p) { int iSelStart = m_iSelectionBegin; - // TODO Refactor: write a function to combine this with the code determining iIMStart and iIMSelectionStart if(iSelStart < m_iFirstVisibleChar) iSelStart = m_iFirstVisibleChar; - int iXLeft = xPositionFromCharIndex(fm,iSelStart,TRUE); - int iXRight = xPositionFromCharIndex(fm,m_iSelectionEnd + 1,TRUE); + int iXLeft = xPositionFromCharIndex(iSelStart); + int iXRight = xPositionFromCharIndex(m_iSelectionEnd + 1); - p->fillRect(iXLeft,1,iXRight - iXLeft,iWidgetHeight,KVI_OPTION_COLOR(KviOption_colorInputSelectionBackground)); + p->fillRect(iXLeft,0,iXRight - iXLeft,rect.height(),KVI_OPTION_COLOR(KviOption_colorInputSelectionBackground)); } // When m_bIMComposing is true, the text between m_iIMStart and m_iIMStart+m_iIMLength should be highlighted to show that this is the active @@ -295,28 +338,25 @@ void KviInputEditor::drawContents(QPainter * p) // while in IM composition mode if(m_bIMComposing && m_iIMLength > 0) { - // TODO Write a function to combine IM selection drawing code. maybe the preedit area too. int iIMSelectionStart = m_iIMSelectionBegin; if(iIMSelectionStart < m_iFirstVisibleChar) iIMSelectionStart = m_iFirstVisibleChar; - int iXIMSelectionLeft = xPositionFromCharIndex(fm,iIMSelectionStart,TRUE); - int iXIMSelectionRight = xPositionFromCharIndex(fm,iIMSelectionStart + m_iIMSelectionLength,TRUE); - p->fillRect(iXIMSelectionLeft,1,iXIMSelectionRight - iXIMSelectionLeft, iWidgetHeight,KVI_OPTION_COLOR(KviOption_colorInputSelectionBackground)); + int iXIMSelectionLeft = xPositionFromCharIndex(iIMSelectionStart); + int iXIMSelectionRight = xPositionFromCharIndex(iIMSelectionStart + m_iIMSelectionLength); + p->fillRect(iXIMSelectionLeft,iTop,iXIMSelectionRight - iXIMSelectionLeft, iBottom,KVI_OPTION_COLOR(KviOption_colorInputSelectionBackground)); // highlight the IM selection int iIMStart = m_iIMStart; if(m_iIMStart < m_iFirstVisibleChar) m_iIMStart = m_iFirstVisibleChar; - int xIMLeft = xPositionFromCharIndex(fm,iIMStart,TRUE); - int xIMRight = xPositionFromCharIndex(fm,iIMStart + m_iIMLength,TRUE); + int xIMLeft = xPositionFromCharIndex(iIMStart); + int xIMRight = xPositionFromCharIndex(iIMStart + m_iIMLength); // underline the IM preedit // Maybe should be put in drawTextBlock, similar to drawing underlined text p->drawLine(xIMLeft, iBottom, xIMRight, iBottom); } - p->setClipping(false); - while((iCharIdx < ((int)(m_szTextBuffer.length()))) && (iCurXPos < iMaxXPos)) { extractNextBlock(iCharIdx,fm,iCurXPos,iMaxXPos); @@ -331,7 +371,7 @@ void KviInputEditor::drawContents(QPainter * p) p->drawText(iCurXPos + 2,iTextBaseline,s); - p->drawRect(iCurXPos,iTop,m_iBlockWidth-1,iBottom-iTop); + p->drawRect(iCurXPos,iTop,m_iBlockWidth-1,iBottom-1); } else { if(m_iSelectionBegin!=-1) { @@ -349,7 +389,7 @@ void KviInputEditor::drawContents(QPainter * p) if(iSubLen) { - drawTextBlock(p,fm,iCurXPos,iTextBaseline,iSubStart,iSubLen,FALSE); + drawTextBlock(p,iTop,iBottom,iCurXPos,iTextBaseline,iSubStart,iSubLen,FALSE); iCurXPos += m_iBlockWidth; m_iBlockWidth=0; } @@ -360,7 +400,7 @@ void KviInputEditor::drawContents(QPainter * p) if(iSubLen) { - drawTextBlock(p,fm,iCurXPos,iTextBaseline,iSubStart,iSubLen,TRUE); + drawTextBlock(p,iTop,iBottom,iCurXPos,iTextBaseline,iSubStart,iSubLen,TRUE); iCurXPos += m_iBlockWidth; m_iBlockWidth=0; } @@ -369,13 +409,13 @@ void KviInputEditor::drawContents(QPainter * p) { iSubStart += iSubLen; iSubLen = iBlockEnd-iSubStart; - drawTextBlock(p,fm,iCurXPos,iTextBaseline,iSubStart,iSubLen,FALSE); + drawTextBlock(p,iTop,iBottom,iCurXPos,iTextBaseline,iSubStart,iSubLen,FALSE); } } else { - drawTextBlock(p,fm,iCurXPos,iTextBaseline,iCharIdx,m_iBlockLen); + drawTextBlock(p,iTop,iBottom,iCurXPos,iTextBaseline,iCharIdx,m_iBlockLen); } } else { - drawTextBlock(p,fm,iCurXPos,iTextBaseline,iCharIdx,m_iBlockLen); + drawTextBlock(p,iTop,iBottom,iCurXPos,iTextBaseline,iCharIdx,m_iBlockLen); } } @@ -384,7 +424,7 @@ void KviInputEditor::drawContents(QPainter * p) } //Now the cursor - m_iLastCursorXPosition = KVI_INPUT_MARGIN; + m_iLastCursorXPosition = 0; m_iBlockLen = m_iFirstVisibleChar; while(m_iBlockLen < m_iCursorPosition) @@ -397,20 +437,18 @@ void KviInputEditor::drawContents(QPainter * p) if(m_bCursorOn) { p->setPen(KVI_OPTION_COLOR(KviOption_colorInputCursor)); - p->drawLine(m_iLastCursorXPosition,1,m_iLastCursorXPosition,iWidgetHeight); + p->drawLine(m_iLastCursorXPosition,iTop,m_iLastCursorXPosition,iBottom); } else { p->setPen(KVI_OPTION_COLOR(KviOption_colorInputForeground)); } } -void KviInputEditor::drawTextBlock(QPainter * pa, QFontMetrics *fm, int iCurXPos, int iTextBaseline, int iCharIdx, int iLen, bool bSelected) +void KviInputEditor::drawTextBlock(QPainter * pa, int iTop, int iBottom, int iCurXPos, int iTextBaseline, int iIdx, int iLen, bool bSelected) { - QString szTmp = m_szTextBuffer.mid(iCharIdx,iLen); + QFontMetrics * fm = KviInputEditor::getLastFontMetrics(font()); + QString szTmp = m_szTextBuffer.mid(iIdx,iLen); m_iBlockWidth = fm->width(szTmp); - QRect rect = contentsRect(); - int iWidgetHeight = rect.height(); - if(m_iCurFore == KVI_INPUT_DEF_FORE) { pa->setPen( bSelected ? KVI_OPTION_COLOR(KviOption_colorInputSelectionForeground) : KVI_OPTION_COLOR(KviOption_colorInputForeground)); @@ -427,9 +465,9 @@ void KviInputEditor::drawTextBlock(QPainter * pa, QFontMetrics *fm, int iCurXPos { if(((unsigned char)m_iCurBack) > 16) { - pa->fillRect(iCurXPos,2,m_iBlockWidth,iWidgetHeight-3,KVI_OPTION_COLOR(KviOption_colorInputForeground)); + pa->fillRect(iCurXPos,iTop,m_iBlockWidth,iBottom,KVI_OPTION_COLOR(KviOption_colorInputForeground)); } else { - pa->fillRect(iCurXPos,2,m_iBlockWidth,iWidgetHeight-3,KVI_OPTION_MIRCCOLOR((unsigned char)m_iCurBack)); + pa->fillRect(iCurXPos,iTop,m_iBlockWidth,iBottom,KVI_OPTION_MIRCCOLOR((unsigned char)m_iCurBack)); } } @@ -671,7 +709,7 @@ void KviInputEditor::mousePressEvent(QMouseEvent * e) m_iCursorPosition = charIndexFromXPosition(e->pos().x()); //move the cursor to int iAnchorX = xPositionFromCharIndex(m_iCursorPosition); - if(iAnchorX > (width()-frameWidth())) m_iFirstVisibleChar++; + if(iAnchorX > width()) m_iFirstVisibleChar++; m_iSelectionAnchorChar = m_iCursorPosition; selectOneChar(-1); //grabMouse(QCursor(crossCursor)); @@ -1956,7 +1994,7 @@ void KviInputEditor::standardNickCompletion(bool bAddMask, QString & szWord, boo //Funky helpers void KviInputEditor::end() { - m_iLastCursorXPosition = frameWidth(); + m_iLastCursorXPosition = 0; m_iCursorPosition = 0; m_iFirstVisibleChar = 0; while(m_iCursorPosition < ((int)(m_szTextBuffer.length()))) @@ -2037,7 +2075,7 @@ void KviInputEditor::selectOneChar(int iPos) int KviInputEditor::charIndexFromXPosition(int iXPos) { - int iCurXPos = frameWidth()+KVI_INPUT_MARGIN; + int iCurXPos = KVI_INPUT_MARGIN; int iCurChar = m_iFirstVisibleChar; int iBufLen = m_szTextBuffer.length(); @@ -2063,30 +2101,11 @@ int KviInputEditor::charIndexFromXPosition(int iXPos) return iCurChar; } -int KviInputEditor::xPositionFromCharIndex(QFontMetrics *fm, int iChIdx, bool bContentsCoords) +int KviInputEditor::xPositionFromCharIndex(int iChIdx) { - // FIXME: this could use fm->width(m_szTextBuffer,chIdx) - int iCurXPos = bContentsCoords ? KVI_INPUT_MARGIN : frameWidth()+KVI_INPUT_MARGIN; - int iCurChar = m_iFirstVisibleChar; - if(!m_szTextBuffer.isEmpty()) - while(iCurChar < iChIdx) - { - QChar c = m_szTextBuffer.at(iCurChar); - - iCurXPos += (c.unicode() < 256) ? KviInputEditor::g_iInputFontCharWidth[c.unicode()] : fm->width(c); - - iCurChar++; - } - return iCurXPos; -} - -int KviInputEditor::xPositionFromCharIndex(int iChIdx, bool bContentsCoords) -{ - // FIXME: this could use fm->width(m_szTextBuffer,chIdx) - int iCurXPos = bContentsCoords ? KVI_INPUT_MARGIN : frameWidth()+KVI_INPUT_MARGIN; - int iCurChar = m_iFirstVisibleChar; - QFontMetrics *fm = KviInputEditor::getLastFontMetrics(font()); + int iCurXPos = 0; + int iCurChar = m_iFirstVisibleChar; if(!m_szTextBuffer.isEmpty()) while(iCurChar < iChIdx) diff --git a/src/kvirc/ui/kvi_input_editor.h b/src/kvirc/ui/kvi_input_editor.h index ec7cdccf5..e31ee7ffd 100644 --- a/src/kvirc/ui/kvi_input_editor.h +++ b/src/kvirc/ui/kvi_input_editor.h @@ -32,7 +32,7 @@ * \brief Input editor * * \def KVI_INPUT_MAX_BUFFER_SIZE Default maximum buffer size -* \def KVI_INPUT_BORDER Default border +* \def KVI_INPUT_PADDING Default padding * \def KVI_INPUT_MARGIN Default margin * \def KVI_INPUT_BLINK_TIME Cursor blink time...just don't set it to a value less than 100 if you don't want to be lagged by your cursors :) * \def KVI_INPUT_DRAG_TIMEOUT Drag scroll speed...(smaller values = faster) @@ -46,7 +46,6 @@ #include "kvi_string.h" #include "kvi_window.h" -#include <QFrame> #include <QString> #include <QWidget> @@ -56,7 +55,8 @@ class KviUserListView; class KviTalPopupMenu; #define KVI_INPUT_MAX_BUFFER_SIZE 400 -#define KVI_INPUT_BORDER 1 +#define KVI_INPUT_XTRAPADDING 1 +#define KVI_INPUT_PADDING 2 #define KVI_INPUT_MARGIN 2 #define KVI_INPUT_BLINK_TIME 800 #define KVI_INPUT_DRAG_TIMEOUT 80 @@ -71,7 +71,7 @@ class KviTalPopupMenu; * \class KviInputEditor * \brief Input editor class */ -class KVIRC_API KviInputEditor : public QFrame +class KVIRC_API KviInputEditor : public QWidget { //Q_PROPERTY( int KviProperty_FocusOwner READ heightHint ) Q_PROPERTY( int TransparencyCapable READ heightHint ) @@ -226,7 +226,7 @@ public: * \brief Returns true if the input line is in read only state * \return bool */ - bool readOnly() { return m_bReadOnly; }; + bool isReadOnly() const { return m_bReadOnly; }; private: /** * \brief Replaces the word before the cursor @@ -282,7 +282,7 @@ private: * \param bSelected Whether the text is selected * \return void */ - void drawTextBlock(QPainter * pa, QFontMetrics *fm, int iCurXPos, int iTextBaseline, int iIdx, int iLen, bool bSelected = false); + void drawTextBlock(QPainter * pa, int iTop, int iBottom, int iCurXPos, int iTextBaseline, int iIdx, int iLen, bool bSelected = false); /** * \brief Gets the substitute character for control codes @@ -319,20 +319,10 @@ private: /** * \brief Returns the current position from a given character - * \param fm The font metrics * \param iChIdx Th index of the character - * \param bContentsCoords Whether to use the frame width in addiction to the margin * \return int */ - int xPositionFromCharIndex(QFontMetrics *fm, int iChIdx, bool bContentsCoords = false); - - /** - * \brief Returns the current position from a given character - * \param iChIdx Th index of the character - * \param bContentsCoords Whether to use the frame width in addiction to the margin - * \return int - */ - int xPositionFromCharIndex(int iChIdx, bool bContentsCoords = false); + int xPositionFromCharIndex(int iChIdx); /** * \brief Kills the drag timer diff --git a/src/kvirc/ui/kvi_query.cpp b/src/kvirc/ui/kvi_query.cpp index 23b1ab500..aa5546aee 100644 --- a/src/kvirc/ui/kvi_query.cpp +++ b/src/kvirc/ui/kvi_query.cpp @@ -74,7 +74,6 @@ KviQuery::KviQuery(KviFrame * lpFrm, KviConsole * lpConsole, const QString & szN //m_pTopSplitter = new KviTalSplitter(QSplitter::Horizontal,this,"top_splitter"); m_pButtonBox = new KviTalHBox(this); m_pLabel = new KviThemedLabel(m_pButtonBox,"query_label"); - m_pLabel->setAutoHeight(1); updateLabelText(); m_pButtonBox->setStretchFactor(m_pLabel,1); diff --git a/src/kvirc/ui/kvi_themedlabel.cpp b/src/kvirc/ui/kvi_themedlabel.cpp index bf87f6022..11be16abe 100644 --- a/src/kvirc/ui/kvi_themedlabel.cpp +++ b/src/kvirc/ui/kvi_themedlabel.cpp @@ -35,47 +35,36 @@ #endif KviThemedLabel::KviThemedLabel(QWidget * par,const char * name) -: QFrame(par) +: QLabel(par) { setObjectName(name); setFrameStyle(QFrame::Sunken | QFrame::StyledPanel); - applyOptions(); - m_bAutoHeight=0; -} + setContentsMargins(2,2,2,2); + setAutoFillBackground(false); -KviThemedLabel::~KviThemedLabel() -{ -} + 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); -void KviThemedLabel::setText(const char * text) -{ - m_szText = QString(text); - if(m_bAutoHeight) - { - int iHeight=fontMetrics().height()*m_szText.split('\n',QString::SkipEmptyParts).count()+4; - setMinimumHeight(iHeight); - } - update(); + applyOptions(); } -void KviThemedLabel::setText(const QString& text) +KviThemedLabel::~KviThemedLabel() { - m_szText = text; - if(m_bAutoHeight) - { - int iHeight=fontMetrics().height()*m_szText.split('\n',QString::SkipEmptyParts).count()+4; - setMinimumHeight(iHeight); - } - update(); } void KviThemedLabel::applyOptions() { + QPalette pal = palette(); + pal.setBrush(QLabel::foregroundRole(),KVI_OPTION_COLOR(KviOption_colorLabelForeground)); + setPalette(pal); + setFont(KVI_OPTION_FONT(KviOption_fontLabel)); - update(); } -void KviThemedLabel::paintEvent(QPaintEvent *) +void KviThemedLabel::paintEvent(QPaintEvent *e) { QPainter p(this); #ifdef COMPILE_PSEUDO_TRANSPARENCY @@ -105,12 +94,7 @@ void KviThemedLabel::paintEvent(QPaintEvent *) } #endif - QRect r = contentsRect(); - r.setLeft(r.left() + 2); // some margin - - p.setPen(KVI_OPTION_COLOR(KviOption_colorLabelForeground)); - - p.drawText(r,Qt::AlignLeft | Qt::AlignVCenter,m_szText); + QLabel::paintEvent(e); } void KviThemedLabel::mouseDoubleClickEvent(QMouseEvent *) diff --git a/src/kvirc/ui/kvi_themedlabel.h b/src/kvirc/ui/kvi_themedlabel.h index 6a63b3a4e..22fcaf71d 100644 --- a/src/kvirc/ui/kvi_themedlabel.h +++ b/src/kvirc/ui/kvi_themedlabel.h @@ -26,27 +26,20 @@ #include "kvi_settings.h" -#include <QFrame> +#include <QLabel> -class KVIRC_API KviThemedLabel : public QFrame +class KVIRC_API KviThemedLabel : public QLabel { Q_OBJECT Q_PROPERTY(int TransparencyCapable READ dummyRead) public: KviThemedLabel(QWidget * par,const char * name); ~KviThemedLabel(); -private: - QString m_szText; - bool m_bAutoHeight; protected: virtual void paintEvent ( QPaintEvent * event ); virtual void mouseDoubleClickEvent(QMouseEvent *e); public: int dummyRead() const { return 0; }; - void setText(const char * text); - void setText(const QString& text); - QString text() { return m_szText; }; - void setAutoHeight(bool value) { m_bAutoHeight=value; }; void applyOptions(); signals: void doubleClicked(); diff --git a/src/kvirc/ui/kvi_topicw.cpp b/src/kvirc/ui/kvi_topicw.cpp index 7b29152bd..d012d9aea 100644 --- a/src/kvirc/ui/kvi_topicw.cpp +++ b/src/kvirc/ui/kvi_topicw.cpp @@ -44,6 +44,7 @@ #include "kvi_mirccntrl.h" #include "kvi_tal_tooltip.h" #include "kvi_tal_popupmenu.h" +#include "kvi_themedlabel.h" #include <QLineEdit> #include <QPainter> @@ -107,18 +108,22 @@ int KviTopicListBoxItem::width ( const KviTalListWidget * lb ) const KviTopicWidget::KviTopicWidget(QWidget * par,const char * name) -: QFrame(par) +: QWidget(par) { setObjectName(name); - setFrameStyle(QFrame::Sunken | QFrame::StyledPanel); m_pHistory = 0; m_pAccept = 0; m_pDiscard = 0; m_pContextPopup = 0; m_iCursorPosition = 0; m_pInput = 0; + m_pLabel = 0; setAutoFillBackground(false); reset(); + + m_pLabel = new KviThemedLabel(this, "topic_label"); + connect(m_pLabel,SIGNAL(doubleClicked()),this,SLOT(switchMode())); + m_pCompletionBox=new KviTalListWidget(this,"topic_completion_box",Qt::Popup); m_pCompletionBox->setFont( font() ); m_pCompletionBox->setPalette( palette() ); @@ -132,6 +137,7 @@ KviTopicWidget::KviTopicWidget(QWidget * par,const char * name) connect(m_pCompletionBox,SIGNAL(itemSelectionChanged()),this,SLOT(complete())); m_pCompletionBox->hide(); + setContentsMargins(0,0,0,0); applyOptions(); } @@ -153,14 +159,16 @@ void KviTopicWidget::reset() KviTalToolTip::add(this,__tr2qs("No topic message has been received from the server yet")); m_szSetAt = ""; m_szSetBy = ""; - update(); } void KviTopicWidget::applyOptions() { //set the font - setFont(KVI_OPTION_FONT(KviOption_fontInput)); - resizeEvent(0); + QFont newFont(KVI_OPTION_FONT(KviOption_fontInput)); + newFont.setKerning(false); + setFont(newFont); + if(m_pLabel) + m_pLabel->setFont(newFont); } void KviTopicWidget::paintColoredText(QPainter *p, QString text,const QPalette& cg,const QRect & rect) @@ -298,50 +306,11 @@ void KviTopicWidget::paintColoredText(QPainter *p, QString text,const QPalette& } } -void KviTopicWidget::paintEvent(QPaintEvent *) -{ - QPainter pa(this); - if(m_pInput == 0) - drawContents(&pa); -} - -void KviTopicWidget::drawContents(QPainter *p) -{ -#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(rect(), 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 - QPalette colorGroup; - colorGroup.setColor(QPalette::Text,KVI_OPTION_COLOR(KviOption_colorLabelForeground)); - colorGroup.setColor(QPalette::Background,KVI_OPTION_COLOR(KviOption_colorLabelBackground)); - //this ensures the painter won't cover the frame margins with text - p->setClipRect(contentsRect()); - paintColoredText(p,m_szTopic,colorGroup,contentsRect()); -} - void KviTopicWidget::setTopic(const QString & topic) { m_szTopic = topic; + m_pLabel->setText(KviHtmlGenerator::convertToHtml(m_szTopic)); + bool bFound = false; for(QStringList::Iterator it=g_pRecentTopicList->begin();it != g_pRecentTopicList->end(); ++it) { @@ -360,7 +329,6 @@ void KviTopicWidget::setTopic(const QString & topic) g_pRecentTopicList->append(m_szTopic); } updateToolTip(); - update(); } void KviTopicWidget::setTopicSetBy(const QString & setBy) @@ -439,13 +407,22 @@ void KviTopicWidget::updateToolTip() QSize KviTopicWidget::sizeHint() const { QFontMetrics fm(font()); - int hght = fm.lineSpacing() + (frameWidth() << 1) + 4; - int baseline = ((hght + fm.ascent() - fm.descent() + 1) >> 1); - if(baseline < 16)hght += (16 - baseline); - return QSize(width(),hght); + int h = qMax(fm.height(), 14) + 2*(KVI_INPUT_MARGIN + KVI_INPUT_PADDING + KVI_INPUT_XTRAPADDING); + int w = fm.width(QLatin1Char('x')) * 17 + 2*(KVI_INPUT_MARGIN + KVI_INPUT_PADDING + KVI_INPUT_XTRAPADDING); + QStyleOptionFrameV2 option; + option.initFrom(this); + option.rect = rect(); + option.lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, &option, this); + option.midLineWidth = 0; + + option.state |= QStyle::State_Sunken; + option.features = QStyleOptionFrameV2::None; + + return (style()->sizeFromContents(QStyle::CT_LineEdit, &option, QSize(w, h). + expandedTo(QApplication::globalStrut()), this)); } -void KviTopicWidget::mouseDoubleClickEvent(QMouseEvent *) +void KviTopicWidget::switchMode() { int maxlen=-1; QObject * w = parent(); @@ -463,7 +440,7 @@ void KviTopicWidget::mouseDoubleClickEvent(QMouseEvent *) } break; } - w = w->parent(); + w = w->parent(); } if(m_pInput == 0) { @@ -471,7 +448,7 @@ void KviTopicWidget::mouseDoubleClickEvent(QMouseEvent *) m_pInput->setObjectName("topicw_inputeditor"); m_pInput->setReadOnly(!bCanEdit); m_pInput->setMaxBufferSize(maxlen); - m_pInput->setGeometry(2,2,width() - (height() << 2)+height(),height()); + m_pInput->setGeometry(0,0,width() - (height() << 2)+height(),height()); m_pInput->setText(m_szTopic); connect(m_pInput,SIGNAL(enterPressed()),this,SLOT(acceptClicked())); connect(m_pInput,SIGNAL(escapePressed()),this,SLOT(discardClicked())); @@ -505,6 +482,10 @@ void KviTopicWidget::mouseDoubleClickEvent(QMouseEvent *) m_pInput->home(); m_pInput->show(); m_pInput->setFocus(); + + m_pLabel->hide(); + } else { + deactivate(); } } @@ -584,32 +565,25 @@ bool KviTopicWidget::eventFilter(QObject *object,QEvent *e) break; } } - return QFrame::eventFilter(object,e); -} - -bool KviTopicWidget::handleKeyPressEvent(QKeyEvent *) -{ - return 1; + return QWidget::eventFilter(object,e); } void KviTopicWidget::keyPressEvent(QKeyEvent * e) { - if(handleKeyPressEvent(e)) - { - e->accept(); - return; - } + e->accept(); + return; } -void KviTopicWidget::resizeEvent(QResizeEvent *e) +void KviTopicWidget::resizeEvent(QResizeEvent *) { - if(e)QFrame::resizeEvent(e); if(m_pInput) { m_pInput->setGeometry(0,0,width() - (height() << 2)+height(),height()); m_pHistory->setGeometry(width() - (height() << 2)+height(),0,height(),height()); m_pAccept->setGeometry(width() - (height() << 1),0,height(),height()); m_pDiscard->setGeometry(width() - height(),0,height(),height()); + } else { + m_pLabel->setGeometry(3,3,width()-6,height()-6); } } @@ -628,6 +602,8 @@ void KviTopicWidget::deactivate() m_pDiscard = 0; } + m_pLabel->show(); + resizeEvent(0); // try to find a KviWindow parent and give it the focus QObject * w = parent(); @@ -676,7 +652,7 @@ void KviTopicWidget::historyClicked() void KviTopicWidget::acceptClicked() { - if(!m_pInput->readOnly()) + if(!m_pInput->isReadOnly()) { QString tmp = m_pInput->text(); if(tmp != m_szTopic)emit topicSelected(tmp); @@ -695,10 +671,6 @@ void KviTopicWidget::insertText(const QString &c) m_pInput->insertText(c); } -int KviTopicWidget::xCursorPostionCalculation(int) -{ - return 0; -} void KviTopicWidget::complete() { if(m_pCompletionBox->selectedItems().count() >0) diff --git a/src/kvirc/ui/kvi_topicw.h b/src/kvirc/ui/kvi_topicw.h index 53d9cf12a..c17fe3d44 100644 --- a/src/kvirc/ui/kvi_topicw.h +++ b/src/kvirc/ui/kvi_topicw.h @@ -38,6 +38,7 @@ class QComboBox; class KviChannel; class KviTalPopupMenu; class KviIrcConnection; +class KviThemedLabel; class KVIRC_API KviTopicListBoxItemDelegate : public KviTalIconAndRichTextItemDelegate { @@ -59,7 +60,7 @@ public: virtual int width(const KviTalListWidget * pList) const; }; -class KVIRC_API KviTopicWidget : public QFrame +class KVIRC_API KviTopicWidget : public QWidget { Q_OBJECT Q_PROPERTY(int TransparencyCapable READ dummyRead) @@ -77,26 +78,21 @@ private: QPushButton * m_pHistory; KviTalPopupMenu * m_pContextPopup; QAbstractItemDelegate * m_pItemDelegate; + KviThemedLabel * m_pLabel; KviInputEditor * m_pInput; KviTalListWidget * m_pCompletionBox; protected: int m_iCursorPosition; private: QChar getSubstituteChar(unsigned short uControlCode); - int xCursorPostionCalculation(int iXInd); protected: void updateToolTip(); void deactivate(); void iconButtonClicked(); virtual bool eventFilter(QObject * o ,QEvent * e); - bool handleKeyPressEvent(QKeyEvent * e); - - virtual void drawContents(QPainter * p); - virtual void mouseDoubleClickEvent(QMouseEvent * e); virtual void mousePressEvent(QMouseEvent * e); virtual void keyPressEvent(QKeyEvent * e); virtual void resizeEvent(QResizeEvent * e); - virtual void paintEvent(QPaintEvent * e); public: void insertChar(QChar c); void insertText(const QString & szText); @@ -122,6 +118,7 @@ protected slots: void copy(); void complete(); void popDownListBox(); + void switchMode(); signals: void topicSelected(const QString & szTopic); }; diff --git a/src/modules/dcc/canvas.cpp b/src/modules/dcc/canvas.cpp index 4c17ae666..4038e969e 100644 --- a/src/modules/dcc/canvas.cpp +++ b/src/modules/dcc/canvas.cpp @@ -49,7 +49,6 @@ #include "kvi_thread.h" #include "kvi_ircsocket.h" #include "kvi_settings.h" - #include "kvi_themedlabel.h" #include "kvi_ircconnection.h" #include <QSplitter> diff --git a/src/modules/dcc/chat.cpp b/src/modules/dcc/chat.cpp index 81e1471ba..981f1c5a6 100644 --- a/src/modules/dcc/chat.cpp +++ b/src/modules/dcc/chat.cpp @@ -90,7 +90,6 @@ KviDccChat::KviDccChat(KviFrame *pFrm,KviDccDescriptor * dcc,const char * name) m_pButtonBox = new KviTalHBox(this); m_pLabel = new KviThemedLabel(m_pButtonBox,"dcc_chat_label"); - m_pLabel->setAutoHeight(1); m_pLabel->setText(name); m_pButtonBox->setStretchFactor(m_pLabel,1); |
