[rkward-cvs] rkward/rkward/misc rkobjectlistview.cpp,1.14,1.15 rkobjectlistview.h,1.3,1.4
Thomas Friedrichsmeier
tfry at users.sourceforge.net
Mon Apr 17 21:30:45 UTC 2006
Update of /cvsroot/rkward/rkward/rkward/misc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28985/rkward/misc
Modified Files:
rkobjectlistview.cpp rkobjectlistview.h
Log Message:
Saner column width for RKObjectListView
Index: rkobjectlistview.h
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkobjectlistview.h,v
retrieving revision 1.3
retrieving revision 1.4
diff -C2 -d -r1.3 -r1.4
*** rkobjectlistview.h 22 Apr 2005 14:52:55 -0000 1.3
--- rkobjectlistview.h 17 Apr 2006 21:30:42 -0000 1.4
***************
*** 23,26 ****
--- 23,27 ----
class RObject;
class QPopupMenu;
+ class RKListViewItem;
/**
***************
*** 38,43 ****
/** Takes care initializing the RKObjectListView (delayed, as the RObjectList may not have been created, yet) and of getting the current list of objects from the RObjectList if fetch_list is set to true*/
void initialize (bool fetch_list);
! /** @returns the RObject corresponding to the given QListViewItem or 0 if no such item is known. */
! RObject *findItemObject (QListViewItem *item);
/** This function returns a pointer to the context menu of the RKObjectListView. It is provided so you can add your own items.
--- 39,44 ----
/** Takes care initializing the RKObjectListView (delayed, as the RObjectList may not have been created, yet) and of getting the current list of objects from the RObjectList if fetch_list is set to true*/
void initialize (bool fetch_list);
! /** @returns the RObject corresponding to the given RKListViewItem or 0 if no such item is known. */
! RObject *findItemObject (RKListViewItem *item);
/** This function returns a pointer to the context menu of the RKObjectListView. It is provided so you can add your own items.
***************
*** 52,56 ****
/** This signal is emitted just before the context-menu is shown. If you connect to this signal, you can make some adjustments to the context-menu.
If you set *suppress to true, showing the context menu will be suppressed. */
! void aboutToShowContextMenu (QListViewItem *item, bool *suppress);
public slots:
void updateComplete ();
--- 53,57 ----
/** This signal is emitted just before the context-menu is shown. If you connect to this signal, you can make some adjustments to the context-menu.
If you set *suppress to true, showing the context menu will be suppressed. */
! void aboutToShowContextMenu (RKListViewItem *item, bool *suppress);
public slots:
void updateComplete ();
***************
*** 67,77 ****
virtual void popupConfigure ();
private:
! // TODO: keep an additional map from RObject to QListViewItem, in order to make this (often called) more efficient
! QListViewItem *findObjectItem (RObject *object);
! void updateItem (QListViewItem *item, RObject *object);
! void addObject (QListViewItem *parent, RObject *object, bool recursive);
! typedef QMap<QListViewItem *, RObject *> ObjectMap;
ObjectMap object_map;
--- 68,78 ----
virtual void popupConfigure ();
private:
! // TODO: keep an additional map from RObject to RKListViewItem, in order to make this (often called) more efficient
! RKListViewItem *findObjectItem (RObject *object);
! void updateItem (RKListViewItem *item, RObject *object);
! void addObject (RKListViewItem *parent, RObject *object, bool recursive);
! typedef QMap<RKListViewItem *, RObject *> ObjectMap;
ObjectMap object_map;
***************
*** 83,85 ****
--- 84,99 ----
};
+ /** This subclass of RKListViewItem reimplements the width ()-function to return 0 if the item is not currently visible. This is needed to get a sane column width in the listview. Also limit maximum default width to 200 px (TODO: make this configurable)
+
+ @author Thomas Friedrichsmeier
+ */
+ class RKListViewItem : public QListViewItem {
+ public:
+ RKListViewItem (QListView *parent) : QListViewItem (parent) {};
+ RKListViewItem (QListViewItem *parent) : QListViewItem (parent) {};
+ ~RKListViewItem () {};
+
+ int RKListViewItem::width (const QFontMetrics &fm, const QListView * lv, int c) const;
+ };
+
#endif
Index: rkobjectlistview.cpp
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/rkobjectlistview.cpp,v
retrieving revision 1.14
retrieving revision 1.15
diff -C2 -d -r1.14 -r1.15
*** rkobjectlistview.cpp 9 Dec 2005 14:05:15 -0000 1.14
--- rkobjectlistview.cpp 17 Apr 2006 21:30:42 -0000 1.15
***************
*** 51,54 ****
--- 51,56 ----
void RKObjectListView::objectBrowserSettingsChanged () {
+ setColumnWidth (0, 50);
+ setColumnWidthMode (0, QListView::Maximum);
if (RKSettingsModuleObjectBrowser::showLabelField ()) {
setColumnWidth (1, 50);
***************
*** 78,82 ****
for (QListViewItemIterator it (this); it.current (); ++it) {
! RObject *object = findItemObject (it.current ());
RK_ASSERT (object);
--- 80,84 ----
for (QListViewItemIterator it (this); it.current (); ++it) {
! RObject *object = findItemObject (static_cast<RKListViewItem*> (it.current ()));
RK_ASSERT (object);
***************
*** 91,100 ****
void RKObjectListView::requestedContextMenu (QListViewItem *item, const QPoint &pos, int) {
! RObject *object = findItemObject (item);
menu_object = object;
bool suppress = false;
! emit (aboutToShowContextMenu (item, &suppress));
if (!suppress) menu->popup (pos);
--- 93,102 ----
void RKObjectListView::requestedContextMenu (QListViewItem *item, const QPoint &pos, int) {
! RObject *object = findItemObject (static_cast<RKListViewItem *> (item));
menu_object = object;
bool suppress = false;
! emit (aboutToShowContextMenu (static_cast<RKListViewItem *> (item), &suppress));
if (!suppress) menu->popup (pos);
***************
*** 136,140 ****
RK_TRACE (APP);
! QListViewItem *parent = findObjectItem (object->getContainer ());
RK_ASSERT (parent);
addObject (parent, object, false);
--- 138,142 ----
RK_TRACE (APP);
! RKListViewItem *parent = findObjectItem (object->getContainer ());
RK_ASSERT (parent);
addObject (parent, object, false);
***************
*** 150,154 ****
RK_TRACE (APP);
! QListViewItem *item = findObjectItem (object);
RK_ASSERT (item);
object_map.remove (item);
--- 152,156 ----
RK_TRACE (APP);
! RKListViewItem *item = findObjectItem (object);
RK_ASSERT (item);
object_map.remove (item);
***************
*** 165,169 ****
RK_TRACE (APP);
! QListViewItem *item = findObjectItem (object);
RK_ASSERT (item);
updateItem (item, object);
--- 167,171 ----
RK_TRACE (APP);
! RKListViewItem *item = findObjectItem (object);
RK_ASSERT (item);
updateItem (item, object);
***************
*** 176,180 ****
}
! QListViewItem *RKObjectListView::findObjectItem (RObject *object) {
RK_TRACE (APP);
for (ObjectMap::iterator it = object_map.begin (); it != object_map.end (); ++it) {
--- 178,182 ----
}
! RKListViewItem *RKObjectListView::findObjectItem (RObject *object) {
RK_TRACE (APP);
for (ObjectMap::iterator it = object_map.begin (); it != object_map.end (); ++it) {
***************
*** 184,188 ****
}
! RObject *RKObjectListView::findItemObject (QListViewItem *item) {
RK_TRACE (APP);
if (!item) return 0;
--- 186,190 ----
}
! RObject *RKObjectListView::findItemObject (RKListViewItem *item) {
RK_TRACE (APP);
if (!item) return 0;
***************
*** 194,198 ****
}
! void RKObjectListView::updateItem (QListViewItem *item, RObject *object) {
RK_TRACE (APP);
--- 196,200 ----
}
! void RKObjectListView::updateItem (RKListViewItem *item, RObject *object) {
RK_TRACE (APP);
***************
*** 232,244 ****
}
! void RKObjectListView::addObject (QListViewItem *parent, RObject *object, bool recursive) {
RK_TRACE (APP);
! QListViewItem *item;
if (parent) {
! item = new QListViewItem (parent);
} else {
! item = new QListViewItem (this);
}
--- 234,246 ----
}
! void RKObjectListView::addObject (RKListViewItem *parent, RObject *object, bool recursive) {
RK_TRACE (APP);
! RKListViewItem *item;
if (parent) {
! item = new RKListViewItem (parent);
} else {
! item = new RKListViewItem (this);
}
***************
*** 277,279 ****
--- 279,296 ----
}
+
+
+ //////////////////// RKListViewItem //////////////////////////
+ int RKListViewItem::width (const QFontMetrics &fm, const QListView * lv, int c) const {
+ if (parent ()) {
+ if (!parent ()->isOpen ()) {
+ return 0;
+ }
+ }
+
+ int ret = QListViewItem::width (fm, lv, c);
+ if (ret > 200) return 200;
+ return ret;
+ }
+
#include "rkobjectlistview.moc"
More information about the rkward-tracker
mailing list