[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: koffice/lib/kopainter
From: Adrian Page <adrian () pagenet ! plus ! com>
Date: 2004-07-16 16:54:59
Message-ID: 20040716165459.548ED9954 () office ! kde ! org
[Download RAW message or body]
CVS commit by page:
Add option to sort icons.
M +76 -3 koIconChooser.cc 1.10
M +6 -1 koIconChooser.h 1.7
--- koffice/lib/kopainter/koIconChooser.cc #1.9:1.10
@@ -60,5 +60,5 @@ void KoPixmapWidget::paintEvent(QPaintEv
-KoIconChooser::KoIconChooser(QSize aIconSize, QWidget *parent, const char *name):
+KoIconChooser::KoIconChooser(QSize aIconSize, QWidget *parent, const char *name, \
bool sort): QGridView(parent, name)
{
@@ -79,4 +79,5 @@ QGridView(parent, name)
mMouseButtonDown = false;
mDragEnabled = false;
+ mSort = sort;
}
@@ -93,7 +94,32 @@ void KoIconChooser::addItem(KoIconItem *
Q_ASSERT(item);
- mIconList.insert(mItemCount++, item);
+
+ int i;
+
+ if (mSort)
+ {
+ i = sortInsertionIndex(item);
+ }
+ else
+ {
+ i = mItemCount;
+ }
+
+ mIconList.insert(i, item);
+ mItemCount++;
calculateCells();
+
+ if (mSort)
+ {
+ for (int c = 0; c < numCols(); c++) {
+ for (int r = 0; r < numRows(); r++) {
+ updateCell(r, c);
+ }
+ }
+ }
+ else
+ {
updateCell(n / numCols(), n - (n / numCols()) * numCols());
+ }
}
@@ -348,4 +374,51 @@ void KoIconChooser::showFullPixmap(const
}
+int KoIconChooser::sortInsertionIndex(const KoIconItem *item)
+{
+ int index = 0;
+
+ if (!mIconList.isEmpty())
+ {
+ // Binary insertion
+ int first = 0;
+ int last = mIconList.count() - 1;
+
+ while (first != last)
+ {
+ int middle = (first + last) / 2;
+
+ if (item -> compare(mIconList.at(middle)) < 0)
+ {
+ last = middle - 1;
+
+ if (last < first)
+ {
+ last = first;
+ }
+ }
+ else
+ {
+ first = middle + 1;
+
+ if (first > last)
+ {
+ first = last;
+ }
+ }
+ }
+
+ if (item -> compare(mIconList.at(first)) < 0)
+ {
+ index = first;
+ }
+ else
+ {
+ index = first + 1;
+ }
+ }
+
+ return index;
+}
+
KoPatternChooser::KoPatternChooser( const QPtrList<KoIconItem> &list, QWidget \
*parent, const char *name ) : QWidget( parent, name )
--- koffice/lib/kopainter/koIconChooser.h #1.6:1.7
@@ -41,4 +41,6 @@ public:
virtual QPixmap &pixmap() const = 0;
virtual QPixmap &thumbPixmap() const = 0;
+ // Return -1 if this is less than other, 0 if equal, 1 if greater than.
+ virtual int compare(const KoIconItem */*other*/) const { return 0; }
};
@@ -60,5 +62,6 @@ class KoIconChooser: public QGridView
Q_OBJECT
public:
- KoIconChooser(QSize iconSize, QWidget *parent = 0L, const char *name = 0L);
+ // To make the items sorted, set 'sort' to true and override \
KoIconItem::compare(). + KoIconChooser(QSize iconSize, QWidget *parent = 0L, const \
char *name = 0L, bool sort = false); virtual ~KoIconChooser();
@@ -94,4 +97,5 @@ private:
void calculateCells();
void showFullPixmap(const QPixmap &pix, const QPoint &p);
+ int sortInsertionIndex(const KoIconItem *item);
private:
@@ -108,4 +112,5 @@ private:
bool mMouseButtonDown;
bool mDragEnabled;
+ bool mSort;
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic