aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Fabio Bas2009-07-22 13:19:51 +0000
committerGravatar Fabio Bas2009-07-22 13:19:51 +0000
commit4cd1ea64618357760a99ae433d97b9f620adaae3 (patch)
tree86055e0bffa3ca5cd2d1ca1cc1d53512cdddea44
parent[KVIrc] (trunk) Reduce templ. class to templ. function. (diff)
downloadKVIrc-4cd1ea64618357760a99ae433d97b9f620adaae3.tar.gz
KVIrc-4cd1ea64618357760a99ae433d97b9f620adaae3.tar.bz2
KVIrc-4cd1ea64618357760a99ae433d97b9f620adaae3.zip
huge performance gain in kvitreewindowlist (fixes #200)
removed a misleding sentence in app_setup git-svn-id: https://svn.kvirc.de/svn/trunk/kvirc@3367 17fca916-40b9-46aa-a4ea-0a15b648b75c
-rw-r--r--src/kvirc/kernel/kvi_app_setup.cpp1
-rw-r--r--src/kvirc/ui/kvi_windowlist_tree.cpp186
-rw-r--r--src/kvirc/ui/kvi_windowlist_tree.h50
3 files changed, 40 insertions, 197 deletions
diff --git a/src/kvirc/kernel/kvi_app_setup.cpp b/src/kvirc/kernel/kvi_app_setup.cpp
index 94e426d2c..42fd71cc1 100644
--- a/src/kvirc/kernel/kvi_app_setup.cpp
+++ b/src/kvirc/kernel/kvi_app_setup.cpp
@@ -537,7 +537,6 @@ void KviApp::findGlobalKvircDirectory()
if(checkGlobalKvircDirectory(m_szGlobalKvircDir))return;
KviMessageBox::warning("Unable to find the shared Kvirc directory.\n"\
- "The usual path for this directory is c:\\kvirc\\" KVI_VERSION_BRANCH "\\.\n"\
"I have tried %Q, but it seemed to fail\n" \
"Trying to run anyway...\n",&m_szGlobalKvircDir);
#else
diff --git a/src/kvirc/ui/kvi_windowlist_tree.cpp b/src/kvirc/ui/kvi_windowlist_tree.cpp
index c9256f0c3..8a2f403ef 100644
--- a/src/kvirc/ui/kvi_windowlist_tree.cpp
+++ b/src/kvirc/ui/kvi_windowlist_tree.cpp
@@ -44,33 +44,19 @@
extern QPixmap * g_pActivityMeterPixmap;
-#define KVI_NUM_STEPS 20
-#define KVI_TIMER_DELAY 18
-
-
// KviTreeWindowListItem
-KviTreeWindowListItem::KviTreeWindowListItem(KviTalTreeWidget * par,KviWindow * wnd)
-: KviTalTreeWidgetItem(par) , KviWindowListItem(wnd)
+KviTreeWindowListItem::KviTreeWindowListItem(QTreeWidget * par,KviWindow * wnd)
+: QTreeWidgetItem(par) , KviWindowListItem(wnd)
{
- m_iStepNumber=0;
- m_bIncreasing=0;
- m_pInternal=new KviTreeWindowListItemInternal(this);
- m_pAnimTimer=new QTimer();
- QObject::connect( m_pAnimTimer, SIGNAL(timeout()), m_pInternal, SLOT(timerShot()));
applyOptions();
//sort the widget
treeWidget()->sortItems(0,Qt::AscendingOrder);
}
KviTreeWindowListItem::KviTreeWindowListItem(KviTreeWindowListItem * par,KviWindow * wnd)
-: KviTalTreeWidgetItem(par) , KviWindowListItem(wnd)
+: QTreeWidgetItem(par) , KviWindowListItem(wnd)
{
- m_iStepNumber=0;
- m_bIncreasing=0;
- m_pInternal=new KviTreeWindowListItemInternal(this);
- m_pAnimTimer=new QTimer();
- QObject::connect( m_pAnimTimer, SIGNAL(timeout()), m_pInternal, SLOT(timerShot()));
applyOptions();
//sort the widget
treeWidget()->sortItems(0,Qt::AscendingOrder);
@@ -78,18 +64,13 @@ KviTreeWindowListItem::KviTreeWindowListItem(KviTreeWindowListItem * par,KviWind
KviTreeWindowListItem::~KviTreeWindowListItem()
{
- KviTalTreeWidget* pView=(KviTalTreeWidget *)treeWidget();
+ KviTreeWindowListTreeWidget* pView= (KviTreeWindowListTreeWidget*)treeWidget();
if(pView)
- if(((KviTreeWindowListTreeWidget*)(pView))->m_pPrevItem==this) ((KviTreeWindowListTreeWidget*)(treeWidget()))->m_pPrevItem=0;
- delete m_pAnimTimer;
- delete m_pInternal;
+ if(pView->m_pPrevItem==this) pView->m_pPrevItem=0;
}
void KviTreeWindowListItem::applyOptions()
{
- setData(0, KVI_TTBID_REDDIFF, (KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveBackground).red()-KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground).red())/KVI_NUM_STEPS);
- setData(0, KVI_TTBID_GREENDIFF, (KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveBackground).green()-KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground).green())/KVI_NUM_STEPS);
- setData(0, KVI_TTBID_BLUEDIFF, (KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveBackground).blue()-KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground).blue())/KVI_NUM_STEPS);
}
void KviTreeWindowListItem::captionChanged()
@@ -176,64 +157,20 @@ QString KviTreeWindowListItem::key() const
return ret;
}
-void KviTreeWindowListItem::timerShot()
-{
- if(m_bIncreasing)
- m_iStepNumber++;
- else
- m_iStepNumber--;
-
- if((m_iStepNumber>=KVI_NUM_STEPS) && m_bIncreasing)
- {
- if(m_pAnimTimer->isActive()) m_pAnimTimer->stop();
- m_iStepNumber=KVI_NUM_STEPS; //make shure, that we cannot get out of range
- } else if((m_iStepNumber<=0) && !m_bIncreasing) {
- if(m_pAnimTimer->isActive()) m_pAnimTimer->stop();
- m_iStepNumber=0; //make shure, that we cannot get out of range
- }
- setData(0, KVI_TTBID_STEPNUM, m_iStepNumber);
-
- QRect rect = treeWidget()->visualItemRect(this);
- treeWidget()->update(QRect(0, rect.top(), rect.left()+rect.width(), rect.height()));
-}
-
-void KviTreeWindowListItem::mouseEnter()
-{
- if(KVI_OPTION_BOOL(KviOption_boolEnableVisualEffects))
- {
- m_bIncreasing=true;
- if(!m_pAnimTimer->isActive()) m_pAnimTimer->start(KVI_TIMER_DELAY);
- }
-}
-
-void KviTreeWindowListItem::mouseLeave()
-{
- if(KVI_OPTION_BOOL(KviOption_boolEnableVisualEffects))
- {
- m_bIncreasing=false;
- if(!m_pAnimTimer->isActive()) m_pAnimTimer->start(KVI_TIMER_DELAY);
- }
-}
-
// KviTreeWindowListTreeWidget
KviTreeWindowListTreeWidget::KviTreeWindowListTreeWidget(QWidget * par)
-: KviTalTreeWidget(par)
+: QTreeWidget(par)
{
setObjectName("tree_windowlist");
setRootIsDecorated(true);
//Animation creates problem with the background painting on expande/collapse
//setAnimated(true);
- setAutoFillBackground(false);
setSelectionMode(QAbstractItemView::SingleSelection);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFont(KVI_OPTION_FONT(KviOption_fontTreeWindowList));
setFocusPolicy(Qt::NoFocus);
setFrameShape(NoFrame);
-
- viewport()->setAutoFillBackground(false);
- viewport()->setMouseTracking(TRUE);
-
m_pPrevItem=0;
}
@@ -241,27 +178,6 @@ KviTreeWindowListTreeWidget::~KviTreeWindowListTreeWidget()
{
}
-void KviTreeWindowListTreeWidget::mouseMoveEvent ( QMouseEvent * e )
-{
- KviTreeWindowListItem* pCur=(KviTreeWindowListItem*)(itemAt(e->pos()));
- if(pCur!=m_pPrevItem)
- {
- if(m_pPrevItem)m_pPrevItem->mouseLeave();
- if(pCur) pCur->mouseEnter();
- setCursor(Qt::PointingHandCursor);
- m_pPrevItem=pCur;
- } else if(!pCur) {
- setCursor(Qt::ArrowCursor);
- }
-}
-
-void KviTreeWindowListTreeWidget::leaveEvent(QEvent *)
-{
- if(m_pPrevItem) m_pPrevItem->mouseLeave();
- m_pPrevItem=0;
- setCursor(Qt::ArrowCursor);
-}
-
void KviTreeWindowListTreeWidget::mousePressEvent(QMouseEvent *e)
{
@@ -281,7 +197,7 @@ void KviTreeWindowListTreeWidget::mousePressEvent(QMouseEvent *e)
if((g_pActiveWindow != wnd) || (wnd->isMinimized()))
{
g_pFrame->setActiveWindow(wnd);
- KviTalTreeWidget::mousePressEvent(e);
+ QTreeWidget::mousePressEvent(e);
} else wnd->minimize();
}
@@ -309,7 +225,7 @@ void KviTreeWindowListTreeWidget::mousePressEvent(QMouseEvent *e)
void KviTreeWindowListTreeWidget::mouseDoubleClickEvent(QMouseEvent * e)
{
- KviTalTreeWidgetItem * it = (KviTalTreeWidgetItem *)itemAt(e->pos());
+ QTreeWidgetItem * it = itemAt(e->pos());
if(it)
{
if(e->button() & Qt::LeftButton)
@@ -366,7 +282,7 @@ void KviTreeWindowListTreeWidget::paintEvent(QPaintEvent * event)
delete p;
//call paint on all childrens
- KviTalTreeWidget::paintEvent(event);
+ QTreeWidget::paintEvent(event);
}
// KviTreeWindowList
@@ -427,7 +343,7 @@ void KviTreeWindowList::tipRequest(KviDynamicToolTip *,const QPoint &pnt)
{
if(KVI_OPTION_BOOL(KviOption_boolShowWindowListToolTips))
{
- KviTalTreeWidgetItem * it = (KviTalTreeWidgetItem *)m_pTreeWidget->itemAt(pnt);
+ QTreeWidgetItem * it = m_pTreeWidget->itemAt(pnt);
if(it)
{
QString szText;
@@ -532,8 +448,8 @@ KviWindowListItem * KviTreeWindowList::lastItem()
bool KviTreeWindowList::setIterationPointer(KviWindowListItem * it)
{
m_pCurrentItem = (KviTreeWindowListItem *)it;
- if(!it)return true;
- if(((KviTalTreeWidget *)m_pTreeWidget) == ((KviTreeWindowListItem *)it)->treeWidget())return true;
+ if(!m_pCurrentItem)return true;
+ if(m_pTreeWidget == m_pCurrentItem->treeWidget())return true;
m_pCurrentItem = 0;
return false;
}
@@ -544,84 +460,35 @@ void KviTreeWindowList::applyOptions()
// KviTreeWindowListItemDelegate
-int KviTreeWindowListItemDelegate::calculateColor(int col1,int col2, int iStepNumber) const
-{
- int result=col1+(col2-col1)/KVI_NUM_STEPS*iStepNumber;
- return result<255 ? result :255;
-}
-
void KviTreeWindowListItemDelegate::paint(QPainter * p, const QStyleOptionViewItem & option, const QModelIndex & index) const
{
- QRect rect=option.rect;
- QRect branchRect = QRect(0, rect.top(), rect.left(), rect.height());
- QRect fullRect = QRect(0, rect.top(), rect.left()+rect.width(), rect.height());
-
QString szText=index.data(Qt::DisplayRole).toString();
- int iStepNumber=index.data(KVI_TTBID_STEPNUM).toInt();
- int iRedDiff=index.data(KVI_TTBID_REDDIFF).toInt();
- int iGreenDiff=index.data(KVI_TTBID_GREENDIFF).toInt();
- int iBlueDiff=index.data(KVI_TTBID_BLUEDIFF).toInt();
- int iHighlightLevel=index.data(KVI_TTBID_HIGHLIGHT).toInt();
int iProgress=index.data(KVI_TTBID_PROGRESS).toInt();
//FIXME not exactly model/view coding style.. but we need to access data on the associated window
KviTreeWindowListTreeWidget* treeWidget = (KviTreeWindowListTreeWidget*)parent();
- KviTreeWindowListItem* item = (KviTreeWindowListItem*) treeWidget->itemFromIndex(index);
- KviWindow* pWindow = item->kviWindow();
+ KviWindow* pWindow = ((KviTreeWindowListItem*)treeWidget->itemFromIndex(index))->kviWindow();
//paint cell background
if (option.state & QStyle::State_Selected)
{
//selection colored background
- p->fillRect(fullRect,KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveBackground));
+ p->fillRect(option.rect, KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveBackground));
} else {
- if(!iStepNumber)
- {
-#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(fullRect, col);
- p->restore();
- } else if(g_pShadedChildGlobalDesktopBackground)
+ if(KVI_OPTION_BOOL(KviOption_boolEnableVisualEffects))
+ if(option.rect.contains(treeWidget->mapFromGlobal(QCursor::pos())))
{
- QPoint pnt = treeWidget->viewport()->mapToGlobal(fullRect.topLeft());
- p->drawTiledPixmap(fullRect,*g_pShadedChildGlobalDesktopBackground,pnt);
- } else {
-#endif
- //background image (if defined)
- QPixmap * pix = KVI_OPTION_PIXMAP(KviOption_pixmapTreeWindowListBackground).pixmap();
- if(pix)
- {
- KviPixmapUtils::drawPixmapWithPainter(p,pix,KVI_OPTION_UINT(KviOption_uintTreeWindowListPixmapAlign),fullRect,fullRect.width(),fullRect.height());
- } else {
- p->fillRect(fullRect,KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground));
- }
-#ifdef COMPILE_PSEUDO_TRANSPARENCY
+ // paint mouse over effect
+ QColor col(KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveBackground));
+ col.setAlpha(127);
+ p->fillRect(option.rect, col);
}
-#endif
- } else {
- // paint mouse over effect
- p->fillRect(fullRect,
- QColor(KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground).red()+iRedDiff*iStepNumber,
- KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground).green()+iGreenDiff*iStepNumber,
- KVI_OPTION_COLOR(KviOption_colorTreeWindowListBackground).blue()+iBlueDiff*iStepNumber
- )
- );
- }
}
-
- //tree branches
- treeWidget->drawBranches(p, branchRect, index);
-
//draw window icon, irc context indicator (a colored square), set font properties for text
- int im = rect.left();
- int yPixmap = (rect.top() + (rect.height() / 2 - 8));
+ int im = option.rect.left();
+ int yPixmap = (option.rect.top() + (option.rect.height() / 2 - 8));
- QRect cRect(im + 3,rect.top(),rect.width(),rect.height());
+ QRect cRect(im + 3,option.rect.top(),option.rect.width(),option.rect.height());
switch(pWindow->type())
{
@@ -695,7 +562,9 @@ void KviTreeWindowListItemDelegate::paint(QPainter * p, const QStyleOptionViewIt
{
p->setPen(KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveForeground));
} else {
+ int iHighlightLevel=index.data(KVI_TTBID_HIGHLIGHT).toInt();
int iLevel;
+
switch(iHighlightLevel)
{
case 0: iLevel = KviOption_colorTreeWindowListForeground; break;
@@ -705,13 +574,16 @@ void KviTreeWindowListItemDelegate::paint(QPainter * p, const QStyleOptionViewIt
case 4: iLevel = KviOption_colorTreeWindowListHighlight4Foreground; break;
default: iLevel = KviOption_colorTreeWindowListHighlight5Foreground; break;
}
- p->setPen(
+
+/* p->setPen(
QColor(
calculateColor(KVI_OPTION_COLOR(iLevel).red(),KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveForeground).red(),iStepNumber),
calculateColor(KVI_OPTION_COLOR(iLevel).green(),KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveForeground).green(),iStepNumber),
calculateColor(KVI_OPTION_COLOR(iLevel).blue(),KVI_OPTION_COLOR(KviOption_colorTreeWindowListActiveForeground).blue(),iStepNumber)
)
);
+*/
+ p->setPen(KVI_OPTION_COLOR(iLevel));
}
//draw window name
diff --git a/src/kvirc/ui/kvi_windowlist_tree.h b/src/kvirc/ui/kvi_windowlist_tree.h
index ae5edfaf4..eeb4bb1c3 100644
--- a/src/kvirc/ui/kvi_windowlist_tree.h
+++ b/src/kvirc/ui/kvi_windowlist_tree.h
@@ -25,27 +25,22 @@
//=============================================================================
#include "kvi_windowlist.h"
-#include "kvi_tal_treewidget.h"
-#include "kvi_tal_itemdelegates.h"
+#include <QTreeWidget>
+#include <QAbstractItemDelegate>
#include <QAbstractItemView>
class KviTreeWindowList;
class KviTreeWindowListItemInternal;
-class KVIRC_API KviTreeWindowListItem : public KviTalTreeWidgetItem , public KviWindowListItem
+class KVIRC_API KviTreeWindowListItem : public QTreeWidgetItem , public KviWindowListItem
{
friend class KviTreeWindowList;
friend class KviTreeWindowListTreeWidget;
friend class KviTreeWindowListItemInternal;
public:
- KviTreeWindowListItem(KviTalTreeWidget * par,KviWindow * wnd);
+ KviTreeWindowListItem(QTreeWidget * par,KviWindow * wnd);
KviTreeWindowListItem(KviTreeWindowListItem * par,KviWindow * wnd);
~KviTreeWindowListItem();
-protected:
- int m_iStepNumber;
- bool m_bIncreasing;
- QTimer* m_pAnimTimer;
- KviTreeWindowListItemInternal *m_pInternal;
public:
virtual QString key() const;
virtual void captionChanged();
@@ -55,29 +50,13 @@ public:
virtual void applyOptions();
protected:
void setActive(bool bActive);
- void mouseEnter();
- void mouseLeave();
- void timerShot();
- int calculateColor(int col1,int col2);
bool operator<(const QTreeWidgetItem &other)const
{
return key() < ((KviTreeWindowListItem*)&other)->key();
}
};
-class KviTreeWindowListItemInternal : public QObject
-{
- Q_OBJECT
-public:
- KviTreeWindowListItemInternal(KviTreeWindowListItem* pItem):m_pItem(pItem) {};
- ~KviTreeWindowListItemInternal() {};
-protected:
- KviTreeWindowListItem* m_pItem;
-public slots:
- void timerShot() { m_pItem->timerShot();};
-};
-
-class KVIRC_API KviTreeWindowListTreeWidget : public KviTalTreeWidget
+class KVIRC_API KviTreeWindowListTreeWidget : public QTreeWidget
{
friend class KviTreeWindowListItem;
friend class KviTreeWindowListItemDelegate;
@@ -90,13 +69,11 @@ protected:
virtual void mousePressEvent(QMouseEvent *e);
virtual void mouseDoubleClickEvent(QMouseEvent * e);
virtual void paintEvent(QPaintEvent * event);
- virtual void mouseMoveEvent (QMouseEvent * e);
- virtual void leaveEvent(QEvent *);
private:
KviWindowListItem * lastItem();
signals:
- void leftMousePress(KviTalTreeWidgetItem * it);
- void rightMousePress(KviTalTreeWidgetItem * it);
+ void leftMousePress(QTreeWidgetItem * it);
+ void rightMousePress(QTreeWidgetItem * it);
public slots:
void sort();
void reverseSort();
@@ -132,23 +109,18 @@ protected slots:
void tipRequest(KviDynamicToolTip *tip,const QPoint &pnt);
};
-#define KVI_TTBID_STEPNUM Qt::UserRole
-#define KVI_TTBID_REDDIFF Qt::UserRole + 1
-#define KVI_TTBID_GREENDIFF Qt::UserRole + 2
-#define KVI_TTBID_BLUEDIFF Qt::UserRole + 3
-#define KVI_TTBID_HIGHLIGHT Qt::UserRole + 4
-#define KVI_TTBID_PROGRESS Qt::UserRole + 5
+#define KVI_TTBID_HIGHLIGHT Qt::UserRole
+#define KVI_TTBID_PROGRESS Qt::UserRole + 1
-class KVIRC_API KviTreeWindowListItemDelegate : public KviTalIconAndRichTextItemDelegate
+class KVIRC_API KviTreeWindowListItemDelegate : public QAbstractItemDelegate
{
Q_OBJECT
public:
KviTreeWindowListItemDelegate(QAbstractItemView * pWidget=0)
- : KviTalIconAndRichTextItemDelegate(pWidget) {};
+ : QAbstractItemDelegate(pWidget) {};
~KviTreeWindowListItemDelegate(){};
QSize sizeHint(const QStyleOptionViewItem &option,const QModelIndex &index) const;
void paint ( QPainter * painter, const QStyleOptionViewItem & option, const QModelIndex & index ) const;
- int calculateColor(int col1,int col2, int iStepNumber) const;
};
#endif //_KVI_WINDOWLIST_TREE_H_