diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-28 18:31:12 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2011-06-28 18:31:12 +0000 |
commit | 0a80cfd57d271dd44221467efb426675fa470356 (patch) | |
tree | 6f503a31aa078eaf8fa015cf1749808529d49fc9 /src/kvirc/ui/kvi_ipeditor.cpp | |
parent | 3329e5a804e28ef3f5eb51d1e7affdd5a508e8f2 (diff) | |
download | kvirc-0a80cfd57d271dd44221467efb426675fa470356.tar.gz kvirc-0a80cfd57d271dd44221467efb426675fa470356.zip |
TQt4 port kvirc
This enables compilation under both Qt3 and Qt4
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kvirc@1238719 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/kvirc/ui/kvi_ipeditor.cpp')
-rw-r--r-- | src/kvirc/ui/kvi_ipeditor.cpp | 146 |
1 files changed, 61 insertions, 85 deletions
diff --git a/src/kvirc/ui/kvi_ipeditor.cpp b/src/kvirc/ui/kvi_ipeditor.cpp index 13291c2..9d1b363 100644 --- a/src/kvirc/ui/kvi_ipeditor.cpp +++ b/src/kvirc/ui/kvi_ipeditor.cpp @@ -23,18 +23,18 @@ #include "kvi_ipeditor.h" #include "kvi_qcstring.h" -#include <qapplication.h> -#include <qlineedit.h> -#include <qlabel.h> -#include <qframe.h> +#include <tqapplication.h> +#include <tqlineedit.h> +#include <tqlabel.h> +#include <tqframe.h> #include <ctype.h> -#include <qevent.h> +#include <tqevent.h> // FIXME: #warning "THIS COULD GO INTO libkvioptions ?" -KviIpEditor::KviIpEditor(QWidget * parent,AddressType addrType,const QString &ipAddr,const char *name) -:QFrame(parent,name) +KviIpEditor::KviIpEditor(TQWidget * tqparent,AddressType addrType,const TQString &ipAddr,const char *name) +:TQFrame(tqparent,name) { for(int i=0;i<7;i++) @@ -43,12 +43,12 @@ KviIpEditor::KviIpEditor(QWidget * parent,AddressType addrType,const QString &ip m_pLabel[i] = 0; } m_pEdit[7] = 0; - setFrameStyle(QFrame::Sunken|QFrame::StyledPanel); + setFrameStyle(TQFrame::Sunken|TQFrame::StyledPanel); #ifdef COMPILE_USE_QT4 - setBackgroundRole(QPalette::Base); + setBackgroundRole(TQPalette::Base); #else - setBackgroundMode(QWidget::PaletteBase); + setBackgroundMode(TQWidget::PaletteBase); #endif setAddressType(addrType); @@ -63,7 +63,7 @@ KviIpEditor::~KviIpEditor() void KviIpEditor::setEnabled(bool bEnabled) { - QFrame::setEnabled(bEnabled); + TQFrame::setEnabled(bEnabled); for(int i=0;i<8;i++) { if(m_pEdit[i])m_pEdit[i]->setEnabled(bEnabled); @@ -71,17 +71,17 @@ void KviIpEditor::setEnabled(bool bEnabled) { // Is this the right way ? #ifdef COMPILE_USE_QT4 - m_pLabel[i]->setBackgroundRole(isEnabled() ? QPalette::Base : QPalette::Background); + m_pLabel[i]->setBackgroundRole(isEnabled() ? TQPalette::Base : TQPalette::Background); #else - m_pLabel[i]->setBackgroundMode(isEnabled() ? QWidget::PaletteBase : QWidget::PaletteBackground); + m_pLabel[i]->setBackgroundMode(isEnabled() ? TQWidget::PaletteBase : TQWidget::PaletteBackground); #endif m_pLabel[i]->setEnabled(bEnabled); } } #ifdef COMPILE_USE_QT4 - setBackgroundRole(isEnabled() ? QPalette::Base : QPalette::Background); + setBackgroundRole(isEnabled() ? TQPalette::Base : TQPalette::Background); #else - setBackgroundMode(isEnabled() ? QWidget::PaletteBase : QWidget::PaletteBackground); + setBackgroundMode(isEnabled() ? TQWidget::PaletteBase : TQWidget::PaletteBackground); #endif } @@ -120,13 +120,13 @@ void KviIpEditor::clear() } } -bool KviIpEditor::setAddress(const QString &ipAddr) +bool KviIpEditor::setAddress(const TQString &ipAddr) { // FIXME We could check if the addres // is valid before effectively setting the fields clear(); - KviQCString ip = ipAddr.ascii(); // ip addresses are digits & latin letters abcdef (IpV6) + KviTQCString ip = ipAddr.ascii(); // ip addresses are digits & latin letters abcdef (IpV6) ip = ip.stripWhiteSpace(); const char * c = ip.data(); @@ -140,7 +140,7 @@ bool KviIpEditor::setAddress(const QString &ipAddr) const char *anchor = c; while(isdigit(*c))c++; if(c == anchor)return false; // Invalid empty field - KviQCString str(anchor,(c - anchor) + 1); + KviTQCString str(anchor,(c - anchor) + 1); bool bOk; int num = str.toInt(&bOk); if(!bOk)return false; // should never happen , but just to be sure @@ -156,7 +156,7 @@ bool KviIpEditor::setAddress(const QString &ipAddr) { const char *anchor = c; while(isdigit(*c) || ((tolower(*c) >= 'a') && (tolower(*c) <= 'f')) || ((tolower(*c) >= 'A') && (tolower(*c) <= 'F')))c++; - KviQCString str(anchor,(c - anchor) + 1); + KviTQCString str(anchor,(c - anchor) + 1); if(str.length() > 4)return false; // Too long m_pEdit[i]->setText(str.data()); if(i < 7){ @@ -169,9 +169,9 @@ bool KviIpEditor::setAddress(const QString &ipAddr) return true; } -QString KviIpEditor::address() const +TQString KviIpEditor::address() const { - QString ret; + TQString ret; if(m_addrType == IpV6) { @@ -183,7 +183,7 @@ QString KviIpEditor::address() const } else { for(int i=0;i<4;i++) { - QString tmp = m_pEdit[i]->text(); + TQString tmp = m_pEdit[i]->text(); bool bOk; int num = tmp.toInt(&bOk); if(!bOk)num = 0; @@ -200,29 +200,29 @@ void KviIpEditor::recreateChildren() // A bit slow , but compact bool bIpV4 = (m_addrType == IpV4); int max = bIpV4 ? 4 : 8; - QFontMetrics fm(font()); + TQFontMetrics fm(font()); //int minWidth = fm.width(bIpV4 ? "000" : "AAAA") + 4; for(int i=0;i<max;i++) { if(!m_pEdit[i]){ - m_pEdit[i] = new QLineEdit(this); + m_pEdit[i] = new TQLineEdit(this); m_pEdit[i]->installEventFilter(this); m_pEdit[i]->setFrame(false); - m_pEdit[i]->setAlignment(Qt::AlignCenter); + m_pEdit[i]->tqsetAlignment(TQt::AlignCenter); } //m_pEdit[i]->setMinimumWidth(minWidth); m_pEdit[i]->setMaxLength(bIpV4 ? 3 : 4); m_pEdit[i]->show(); if(i < (max - 1)) { - if(!m_pLabel[i])m_pLabel[i] = new QLabel(this); + if(!m_pLabel[i])m_pLabel[i] = new TQLabel(this); m_pLabel[i]->setText(bIpV4 ? "." : ":"); m_pLabel[i]->show(); // Is this the right way ? setBackgroundMode seems to not work well #ifdef COMPILE_USE_QT4 - m_pLabel[i]->setBackgroundRole(isEnabled() ? QPalette::Base : QPalette::Background); + m_pLabel[i]->setBackgroundRole(isEnabled() ? TQPalette::Base : TQPalette::Background); #else - m_pLabel[i]->setBackgroundMode(isEnabled() ? QWidget::PaletteBase : QWidget::PaletteBackground); + m_pLabel[i]->setBackgroundMode(isEnabled() ? TQWidget::PaletteBase : TQWidget::PaletteBackground); #endif } } @@ -243,35 +243,35 @@ void KviIpEditor::recreateChildren() } } } - //setMinimumWidth(4 + (max * minWidth) + ((max - 1) * m_pLabel[0]->sizeHint().width())); - setMinimumHeight(m_pLabel[0]->sizeHint().height() + 4); + //setMinimumWidth(4 + (max * minWidth) + ((max - 1) * m_pLabel[0]->tqsizeHint().width())); + setMinimumHeight(m_pLabel[0]->tqsizeHint().height() + 4); resizeEvent(0); } -bool KviIpEditor::eventFilter(QObject * o,QEvent *e) +bool KviIpEditor::eventFilter(TQObject * o,TQEvent *e) { - if(o->inherits("QLineEdit")) + if(o->inherits(TQLINEEDIT_OBJECT_NAME_STRING)) { - if(e->type() == QEvent::KeyPress) + if(e->type() == TQEvent::KeyPress) { - QString s; + TQString s; // find the editor int edIdx = -1; for(int i=0;i<8;i++) { - if(m_pEdit[i] == o) + if(TQT_BASE_OBJECT(m_pEdit[i]) == TQT_BASE_OBJECT(o)) { edIdx = i; break; } } - if(edIdx == -1)return QFrame::eventFilter(o,e); // user added QLineEdit child ? + if(edIdx == -1)return TQFrame::eventFilter(o,e); // user added TQLineEdit child ? int edMax = (m_addrType == IpV4) ? 3 : 7; - int cursorPos = ((QLineEdit *)o)->cursorPosition(); - switch(((QKeyEvent *)e)->key()) + int cursorPos = ((TQLineEdit *)o)->cursorPosition(); + switch(((TQKeyEvent *)e)->key()) { - case Qt::Key_Right: - s = ((QLineEdit *)o)->text(); + case TQt::Key_Right: + s = ((TQLineEdit *)o)->text(); if(((unsigned int)cursorPos) == s.length()) { if(edIdx < edMax) @@ -282,8 +282,8 @@ bool KviIpEditor::eventFilter(QObject * o,QEvent *e) } } break; - case Qt::Key_Left: - case Qt::Key_Backspace: + case TQt::Key_Left: + case TQt::Key_Backspace: if(cursorPos == 0) { if(edIdx > 0) @@ -294,26 +294,22 @@ bool KviIpEditor::eventFilter(QObject * o,QEvent *e) return true; } } - return QFrame::eventFilter(o,e); + return TQFrame::eventFilter(o,e); break; - case Qt::Key_End: - case Qt::Key_Home: - case Qt::Key_Delete: - case Qt::Key_Tab: - return QFrame::eventFilter(o,e); + case TQt::Key_End: + case TQt::Key_Home: + case TQt::Key_Delete: + case TQt::Key_Tab: + return TQFrame::eventFilter(o,e); break; default: - // a normal key (this part substitutes a QValidator) - const char c = tolower(((QKeyEvent *)e)->ascii()); + // a normal key (this part substitutes a TQValidator) + const char c = tolower(((TQKeyEvent *)e)->ascii()); if(m_addrType == IpV4) { if((c >= '0') && (c <= '9')) { -#if QT_VERSION >= 300 if(m_pEdit[edIdx]->hasSelectedText())m_pEdit[edIdx]->cut(); -#else - if(m_pEdit[edIdx]->hasMarkedText())m_pEdit[edIdx]->cut(); -#endif cursorPos = m_pEdit[edIdx]->cursorPosition(); s = m_pEdit[edIdx]->text(); s.insert(cursorPos,c); @@ -333,19 +329,11 @@ bool KviIpEditor::eventFilter(QObject * o,QEvent *e) return true; } } -#if QT_VERSION >= 300 m_pEdit[edIdx]->cursorForward(false); -#else - m_pEdit[edIdx]->cursorRight(false); -#endif } else { if((c == '.') && (edIdx < edMax)) { -#if QT_VERSION >= 300 if(!m_pEdit[edIdx]->hasSelectedText()) -#else - if(!m_pEdit[edIdx]->hasMarkedText()) -#endif { m_pEdit[++edIdx]->setFocus(); m_pEdit[edIdx]->selectAll(); @@ -355,11 +343,7 @@ bool KviIpEditor::eventFilter(QObject * o,QEvent *e) } else { if( ((c >= '0') && (c <= '9')) || ((c >= 'a') && (c <= 'f')) ) { -#if QT_VERSION >= 300 if(m_pEdit[edIdx]->hasSelectedText())m_pEdit[edIdx]->cut(); -#else - if(m_pEdit[edIdx]->hasMarkedText())m_pEdit[edIdx]->cut(); -#endif cursorPos = m_pEdit[edIdx]->cursorPosition(); s = m_pEdit[edIdx]->text(); @@ -384,21 +368,13 @@ bool KviIpEditor::eventFilter(QObject * o,QEvent *e) m_pEdit[edIdx]->selectAll(); //m_pEdit[edIdx]->setCursorPosition(0); } else { -#if QT_VERSION >= 300 m_pEdit[edIdx]->cursorForward(false); -#else - m_pEdit[edIdx]->cursorRight(false); -#endif } } } else { if((c == ':') && (edIdx < edMax)) { -#if QT_VERSION >= 300 if(!m_pEdit[edIdx]->hasSelectedText()) -#else - if(!m_pEdit[edIdx]->hasMarkedText()) -#endif { m_pEdit[++edIdx]->setFocus(); m_pEdit[edIdx]->selectAll(); @@ -411,15 +387,15 @@ bool KviIpEditor::eventFilter(QObject * o,QEvent *e) } } } - return QFrame::eventFilter(o,e); + return TQFrame::eventFilter(o,e); } -void KviIpEditor::resizeEvent(QResizeEvent *e) +void KviIpEditor::resizeEvent(TQResizeEvent *e) { if(m_pEdit[0]) { int maxW = (m_addrType == IpV4) ? 4 : 8; - int labHint = m_pLabel[0]->sizeHint().width(); + int labHint = m_pLabel[0]->tqsizeHint().width(); int hghHint = height() - 4; int ediWdth = ((width() - 4) - ((maxW - 1) * labHint)) / maxW; int curX = 2; @@ -434,19 +410,19 @@ void KviIpEditor::resizeEvent(QResizeEvent *e) curX += ediWdth; } } - if(e)QFrame::resizeEvent(e); + if(e)TQFrame::resizeEvent(e); } -QSize KviIpEditor::sizeHint() +TQSize KviIpEditor::tqsizeHint() { if(m_pEdit[0]) { - int labHint = m_pLabel[0]->sizeHint().width(); - int hghHint = m_pEdit[0]->sizeHint().height(); - int ediHint = m_pEdit[0]->sizeHint().width(); - if(m_addrType == IpV4)return QSize((labHint * 3) + (ediHint * 4) + 4,hghHint + 4); - else return QSize((labHint * 7) + (ediHint * 8) + 4,hghHint + 4); - } else return QFrame::sizeHint(); + int labHint = m_pLabel[0]->tqsizeHint().width(); + int hghHint = m_pEdit[0]->tqsizeHint().height(); + int ediHint = m_pEdit[0]->tqsizeHint().width(); + if(m_addrType == IpV4)return TQSize((labHint * 3) + (ediHint * 4) + 4,hghHint + 4); + else return TQSize((labHint * 7) + (ediHint * 8) + 4,hghHint + 4); + } else return TQFrame::tqsizeHint(); } |