2 ** Copyright (C) 1999,2000 Toivo Pedaste <toivo@ucs.uwa.edu.au>
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License as published by
9 ** the Free Software Foundation; either version 2 of the License, or
10 ** (at your option) any later version.
12 ** This program is distributed in the hope that it will be useful,
13 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
14 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 ** GNU General Public License for more details.
17 ** You should have received a copy of the GNU General Public License
18 ** along with this program in a file called COPYING; if not, write to
19 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
20 ** MA 02110-1301, USA.
24 ** Bug reports and questions can be sent to kde-devel@kde.org
27 #include <QtGui/QPixmap>
28 #include <Qt3Support/Q3PtrStack>
30 #include <QtGui/QMouseEvent>
31 #include <QtGui/QFrame>
32 #include <Qt3Support/Q3PtrList>
39 #include "pkgInterface.h"
40 #include "packageInfo.h"
41 #include "managementWidget.h"
42 #include "packageDisplay.h"
47 KpTreeList::KpTreeList( QWidget
*parent
) :
51 setShowSortIndicator(true);
53 Q3PtrStack
<QString
> stack();
55 setFrameStyle(QFrame::Panel
|QFrame::Sunken
);
58 addColumn(i18n("Package"));
59 setColumnWidthMode(0,Q3ListView::Manual
);
60 addColumn(i18n("Mark"));
61 setColumnWidthMode(1,Q3ListView::Manual
);
62 addColumn(i18n("Summary"));
63 setColumnWidthMode(2,Q3ListView::Manual
);
64 addColumn(i18n("Size"));
65 setColumnWidthMode(3,Q3ListView::Manual
);
66 addColumn(i18n("Version"));
67 setColumnWidthMode(4,Q3ListView::Manual
);
68 addColumn(i18n("Old Version"));
69 setColumnWidthMode(5,Q3ListView::Manual
);
71 // setAllColumnsShowFocus(true);
72 // setColumnAlignment(3, Qt::AlignRight);
73 setRootIsDecorated(true);
80 void KpTreeList::clear()
87 KpTreeListItem
*KpTreeList::firstChild()
89 return (KpTreeListItem
*)K3ListView::firstChild();
92 KpTreeListItem
*KpTreeList::currentItem()
94 return (KpTreeListItem
*)K3ListView::currentItem();
97 void KpTreeList::contentsMousePressEvent ( QMouseEvent
* e
)
99 bool markUpdate
= false;
101 if (e
->button() == Qt::LeftButton
) {
102 if (inMark(e
->x())) {
103 QPoint vp
= contentsToViewport(e
->pos());
104 KpTreeListItem
*i
= ( KpTreeListItem
*)itemAt( vp
);
105 if (i
&& i
->childCount() == 0) {
106 if (e
->modifiers() == Qt::ShiftButton
) {
107 if (i
->childCount() == 0) {
111 KpTreeListItem
*item
= i
;
112 while ((item
= (KpTreeListItem
*)item
->itemAbove()) && !item
->marked
) {;}
115 while ((item
= (KpTreeListItem
*)item
->itemAbove()) && !item
->marked
) {
116 if (item
->childCount() == 0) {
123 while ((item
= (KpTreeListItem
*)item
->itemBelow()) && !item
->marked
) {;}
126 while ((item
= (KpTreeListItem
*)item
->itemBelow()) && !item
->marked
) {
127 if (item
->childCount() == 0) {
140 K3ListView::contentsMousePressEvent (e
);
142 K3ListView::contentsMousePressEvent (e
);
150 bool KpTreeList::inMark(int x
) {
154 for (i
= 0; i
< MPOS
; i
++)
155 st
+= columnWidth(i
);
156 return (x
>= st
&& x
<= st
+ columnWidth(MPOS
));
159 ///////////////////////////////////////////////////////////////////////////
161 void KpTreeList::expand()
163 KpTreeListItem
*item
= firstChild();
169 expandChild(item
->firstChild());
170 } while ((item
= item
->nextSibling()));
174 void KpTreeList::expandChild(KpTreeListItem
*it
)
177 if (it
->childCount() > 0) {
178 expandChild(it
->firstChild());
179 it
->setVisible(true);
181 } while ((it
= it
->nextSibling()));
184 ///////////////////////////////////////////////////////////////////////////
186 void KpTreeList::sweep(bool init
)
188 KpTreeListItem
*item
= firstChild();
198 int ret
= sweepChild(item
->firstChild());
200 item
->setVisible(false);
202 } while ((item
= item
->nextSibling()));
205 int KpTreeList::sweepChild(KpTreeListItem
*it
)
210 if (it
->childCount() > 0) {
211 ret
= sweepChild(it
->firstChild());
212 // kDebug()<<"VV="<<it->text(0)<<" "<<it->isVisible()<<" " << ret << "\n";
214 it
->setVisible(false);
220 // kDebug()<<"VV="<<it->text(0)<<" "<<it->isVisible()<<"\n";
221 if (!it
->info
->display(treeType
)) {
222 it
->setVisible(false);
228 } while ((it
= it
->nextSibling()));
233 ///////////////////////////////////////////////////////////////////////////
234 void KpTreeList::clearMarked(KpTreeListItem
*item
)
237 if (item
->childCount() > 0) {
238 clearMarked(item
->firstChild());
240 item
->setMark(false);
241 item
= item
->nextSibling();
245 void KpTreeList::markAll(KpTreeListItem
*item
)
248 if (item
->childCount() > 0) {
249 markAll(item
->firstChild());
252 if (item
->info
->display(treeType
)) {
256 item
= item
->nextSibling();
260 void KpTreeList::findMarked(KpTreeListItem
*item
, Q3PtrList
<KpTreeListItem
> &selList
)
263 if (item
->childCount() > 0) {
264 findMarked(item
->firstChild(), selList
);
267 selList
.insert(0,item
);
269 item
= item
->nextSibling();
273 void KpTreeList::countMarked(KpTreeListItem
*item
, int &cntInstall
, int &cntUnInstall
)
276 if (item
->childCount() > 0) {
277 countMarked(item
->firstChild(), cntInstall
, cntUnInstall
);
280 if (item
->info
->isInstallable())
285 item
= item
->nextSibling();
289 ///////////////////////////////////////////////////////////////////////////
290 void KpTreeList::expandTree(KpTreeList
*list
)
292 KpTreeListItem
*item
= list
->firstChild();
295 if (item
->childCount() > 0) {
299 item
= item
->nextSibling();
304 void KpTreeList::expandTree(KpTreeListItem
*pitem
)
306 KpTreeListItem
*item
= pitem
->firstChild();
309 if (item
->childCount() > 0) {
313 item
= item
->nextSibling();
317 void KpTreeList::collapseTree(KpTreeList
*list
)
319 KpTreeListItem
*item
= list
->firstChild();
322 if (item
->childCount() > 0) {
325 item
= item
->nextSibling();
329 void KpTreeList::collapseTree(KpTreeListItem
*pitem
)
332 KpTreeListItem
*item
= pitem
->firstChild();
335 if (item
->childCount() > 0) {
339 item
= item
->nextSibling();
342 pitem
->setOpen(true);
344 pitem
->setOpen(false);
347 ///////////////////////////////////////////////////////////////////////////
348 // A package has been highlighted in the list tree
349 void KpTreeList::packageHighlighted(Q3ListViewItem
*item
, packageDisplayWidget
*packageDisplay
)
351 KpTreeListItem
*sel
= (KpTreeListItem
*)item
;
353 if (!sel
|| sel
->childCount()) {
354 packageDisplay
->changePackage(0);
358 int num
= stack
.count();
359 for (int i
= num
- 1; i
>= n
; i
--) {
365 // Disable the tree list while we do this
368 // Tell everything that is interested to change packages
369 packageDisplay
->changePackage(sel
->info
);
371 // Re-enable the treeList and uninstall button
383 KpTreeListItem
*KpTreeList::search( const QString
&str
, const QString
&head
,
384 KpTreeListItem
*start
)
386 KpTreeListItem
*item
= firstChild();
390 searchSubstr
= false;
395 if (item
->text(0) == head
) {
396 searchChild(item
->firstChild());
397 if (searchResult
!= 0)
400 } while ((item
= item
->nextSibling()));
404 KpTreeListItem
*KpTreeList::search(const QString
&str
, bool subStr
, bool wrap
,
407 kDebug() << "KpTreeList::search2\n";
414 searchCitem
= currentItem();
416 searchSubstr
= subStr
;
420 searchChild(firstChild());
422 return changePack(searchResult
);
425 bool KpTreeList::searchChild(KpTreeListItem
*it
)
429 QString s
= it
->text(0);
430 // kDebug() << "s='" << s << "'='" << searchStr << "\n";
431 if ((it
->childCount() == 0) && (it
->info
->display(treeType
)) &&
432 (searchSubstr
? s
.contains(searchStr
, Qt::CaseInsensitive
) : s
== searchStr
)) {
438 if (searchCitem
== it
) {
446 if (it
->childCount() > 0) {
447 if (searchChild(it
->firstChild()))
450 } while ((it
= it
->nextSibling()));
454 KpTreeListItem
*KpTreeList::changePack(KpTreeListItem
*searchResult
, bool push
)
460 while ((i
= i
->parent())) {
464 stack
.append(searchResult
);
465 kpkg
->enablePrevious();
469 setSelected(searchResult
,true);
470 setCurrentItem(searchResult
);
471 ensureItemVisible(searchResult
);
478 void KpTreeList::next()
481 KpTreeListItem
*s
= stack
.at(n
+ 1);
483 changePack(s
, false);
485 if (n
>= int(stack
.count() - 2)) {
489 kpkg
->enablePrevious();
493 void KpTreeList::previous()
496 KpTreeListItem
*s
= stack
.at(n
-1);
499 changePack(s
, false);
503 kpkg
->disablePrevious();
505 if (n
< int(stack
.count() - 2)) {
510 void KpTreeList::stackRemove(KpTreeListItem
*pack
)
512 int n
= stack
.find(pack
);
515 kpkg
->disablePrevious();
517 if (n
>= int(stack
.count() - 1)) {
525 //////////////////////////////////////////////////////////////////////////////
527 void KpTreeList::writeTreePos()
530 KConfigGroup
config(KGlobal::config(), "Treelist");
536 for (i
= 0; i
< 6; i
++) {
538 config
.writeEntry(colpos
,columnWidth(i
));
542 void KpTreeList::readTreePos()
544 kDebug() << "KpTreeList::readTreePos()" << "\n";
545 KConfigGroup
config(KGlobal::config(), "Treelist");
546 restoreLayout(config
);
550 int num
[] = {185,37,180,54,95,95};
556 for (i
= 0; i
< 6; i
++) {
558 n
= config
.readEntry(colpos
,num
[i
]);
565 //////////////////////////////////////////////////////////////////////////////
566 //////////////////////////////////////////////////////////////////////////////
567 KpTreeListItem::KpTreeListItem( Q3ListViewItem
*parent
, packageInfo
* pinfo
,
568 const QPixmap
& thePixmap
,
569 QString label1
, QString label2
,
570 QString label3
, QString label4
,
571 QString label5
, QString label6
,
572 QString label7
, QString label8
574 ) : Q3ListViewItem(parent
, label1
, label2
, label3
, label4
, label5
,
575 label6
, label7
, label8
)
579 setPixmap(0, thePixmap
);
580 if (!label2
.isNull())
581 setPixmap(1,info
->interface
->markUnInst
);
584 KpTreeListItem::KpTreeListItem( K3ListView
*parent
, packageInfo
* pinfo
,
585 const QPixmap
& thePixmap
,
586 QString label1
, QString label2
,
587 QString label3
, QString label4
,
588 QString label5
, QString label6
,
589 QString label7
, QString label8
590 ) : Q3ListViewItem(parent
, label1
, label2
, label3
, label4
, label5
,
591 label6
, label7
, label8
)
595 setPixmap(0, thePixmap
);
596 if (!label2
.isNull())
597 setPixmap(1,info
->interface
->markUnInst
);
600 KpTreeListItem
*KpTreeListItem::firstChild()
602 return (KpTreeListItem
*)Q3ListViewItem::firstChild();
605 KpTreeListItem
*KpTreeListItem::nextSibling()
607 return (KpTreeListItem
*)Q3ListViewItem::nextSibling();
610 void KpTreeListItem::toggleMark()
614 setPixmap(1,info
->interface
->markInst
);
616 setPixmap(1,info
->interface
->markUnInst
);
619 void KpTreeListItem::setMark(bool mark
)
623 setPixmap(1,info
->interface
->markInst
);
626 setPixmap(1,info
->interface
->markUnInst
);
630 void KpTreeListItem::hide()
635 void KpTreeListItem::show()
641 int KpTreeListItem::compare( Q3ListViewItem
*i
, int col
, bool ascending
) const
642 { // Make sorting more certain
643 if (col
== 3) { // size column
647 QRegExp
rx("([0-9.]+)(.*)");
649 j
= key( col
, ascending
);
652 if (rx
.cap(2) == "MB") {
653 vj
= rx
.cap(1).toFloat() * 1000000;
654 } else if (rx
.cap(2) == "kB") {
655 vj
= rx
.cap(1).toFloat() * 1000;
657 vj
= rx
.cap(1).toFloat();
661 k
= i
->key( col
, ascending
);
664 if (rx
.cap(2) == "MB") {
665 vk
= rx
.cap(1).toFloat() * 1000000;
666 } else if (rx
.cap(2) == "kB") {
667 vk
= rx
.cap(1).toFloat() * 1000;
669 vk
= rx
.cap(1).toFloat();
673 // kDebug() << k << "=" << vk << " " << j << "=" << vj << "\n";
681 return Q3ListViewItem::compare(i
, col
, ascending
);
685 #include "kplview.moc"