📄 ciconview.cpp
字号:
/*************************************************************************** CIconView.cpp The IconView class (c) 2000-2003 Beno顃 Minisini <gambas@users.sourceforge.net> This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.***************************************************************************/#define __CICONVIEW_CPP#include <qapplication.h>#include <qheader.h>#include <qpalette.h>#include <qscrollview.h>#include <qiconview.h>#if QT_VERSION >= 0x030200#include <qobjectlist.h>#else#include <qobjcoll.h>#endif#include "gambas.h"#include "CWidget.h"#include "CPicture.h"#include "CIconView.h"DECLARE_EVENT(EVENT_Select); /* selection change */DECLARE_EVENT(EVENT_Click); /* simple click */DECLARE_EVENT(EVENT_Activate); /* double click */DECLARE_EVENT(EVENT_Rename);/*************************************************************************** class MyIconViewItem***************************************************************************/void MyIconViewItem::initData(void){ picture = NULL; key = NULL;}MyIconViewItem::MyIconViewItem(QIconView *parent): QIconViewItem(parent, " "){ initData();}MyIconViewItem::MyIconViewItem(QIconView *parent, MyIconViewItem *after): QIconViewItem(parent, after){ initData();}MyIconViewItem::~MyIconViewItem(){ //CIconView *ob = (CIconView *)CWidget::get(listView()); //if (ob->item == this) // ob->item = NULL; if (container->item == this) container->item = NULL; if (container->last == this) container->last = NULL; container->dict->remove(key); GB.Unref((void **)&picture); GB.FreeString(&key);}void MyIconViewItem::setPicture(GB_OBJECT *pict){ SET_PIXMAP(setPixmap, &picture, pict);}/*************************************************************************** class MyListView***************************************************************************//*static void updateLastColumn(QIconView *lw){ int w, col; col = lw->columns() - 1; w = lw->visibleWidth(); //lw->width() - lw->frameWidth() * 2 - lw->header()->sectionPos(col); lw->setColumnWidth(col, w); //updateScrollBars(); //qDebug("setColumnWidth %d = %d", col, w); lw->header()->resize(w, lw->header()->height() );}*/#if 0MyListView::MyListView(QWidget *parent): QIconView(parent){ setAllColumnsShowFocus(true); setHScrollBarMode(AlwaysOff); addColumn(""); setColumnWidthMode(0, Manual);}void MyListView::viewportResizeEvent(QResizeEvent *e){ //qDebug("> viewportResizeEvent"); QIconView::viewportResizeEvent(e); //GB.Post((void (*)())updateLastColumn, (long)this); updateLastColumn(this); //setColumnWidth(0, viewport()->width()); //qDebug("< viewportResizeEvent");}void MyListView::resizeEvent(QResizeEvent *e){ //qDebug("> resizeEvent"); QIconView::resizeEvent(e); //if (viewport()->width() > columnWidth(0)) //setColumnWidth(0, viewport()->width()); //updateLastColumn(this); //qDebug("< resizeEvent"); //triggerUpdate();}#endif/*************************************************************************** IconView***************************************************************************/BEGIN_METHOD(CICONVIEW_new, GB_OBJECT parent) QIconView *wid = new QIconView(CONTAINER(VARG(parent))); QObject::connect(wid, SIGNAL(selectionChanged()), &CIconView::manager, SLOT(selected())); QObject::connect(wid, SIGNAL(doubleClicked(QIconViewItem *)), &CIconView::manager, SLOT(activated(QIconViewItem *))); QObject::connect(wid, SIGNAL(clicked(QIconViewItem *)), &CIconView::manager, SLOT(clicked(QIconViewItem *))); QObject::connect(wid, SIGNAL(itemRenamed(QIconViewItem *)), &CIconView::manager, SLOT(renamed(QIconViewItem *))); CWIDGET_new(wid, (void *)_object, "IconView"); THIS->dict = new QAsciiDict<MyIconViewItem>; THIS->sorted = false; THIS->asc = true; THIS->item = NULL; THIS->last = NULL; wid->setWordWrapIconText(false); wid->setGridX(64); wid->setGridY(64); wid->setSpacing(8); wid->show();END_METHODBEGIN_METHOD_VOID(CICONVIEW_free) delete THIS->dict; //CALL_METHOD_VOID(CWIDGET_delete);END_METHODBEGIN_METHOD_VOID(CICONVIEW_clear) THIS->dict->clear(); WIDGET->clear();END_METHODBEGIN_METHOD(CICONVIEW_add, GB_STRING key; GB_STRING text; GB_OBJECT picture; GB_STRING after) MyIconViewItem *item; QIconView *wid = WIDGET; char *key = GB.ToZeroString(ARG(key)); MyIconViewItem *after = NULL; char *akey; if (*key == 0) { GB.Error("Null key"); return; } item = (*THIS->dict)[key]; if (item != NULL) { GB.Error("Key already used"); return; } if (!MISSING(after)) { akey = GB.ToZeroString(ARG(after)); if (*akey) { after = (*THIS->dict)[akey]; if (after == NULL) { GB.Error("After item does not exist"); return; } } } if (after == NULL) item = new MyIconViewItem(wid); else item = new MyIconViewItem(wid, after); item->setText(QSTRING_ARG(text)); GB.StoreString(ARG(key), &item->key); THIS->dict->insert(item->key, item); if (!MISSING(picture)) item->setPicture(ARG(picture)); item->container = THIS; THIS->item = item; THIS->last = item; RETURN_SELF();END_METHODBEGIN_METHOD(CICONVIEW_remove, GB_STRING key) MyIconViewItem *item; char *key = GB.ToZeroString(ARG(key)); item = CIconView::getItem(THIS, key); if (!item) return; delete item;END_METHODBEGIN_METHOD(CICONVIEW_exist, GB_STRING key) GB.ReturnBoolean((*THIS->dict)[GB.ToZeroString(ARG(key))] != 0);END_METHODBEGIN_METHOD(CICONVIEW_get, GB_STRING key) MyIconViewItem *item; char *key = GB.ToZeroString(ARG(key)); item = CIconView::getItem(THIS, key); if (!item) return; THIS->item = item; RETURN_SELF();END_METHODBEGIN_PROPERTY(CICONVIEW_mode) if (READ_PROPERTY) GB.ReturnInteger(WIDGET->selectionMode()); else WIDGET->setSelectionMode((QIconView::SelectionMode)VPROP(GB_INTEGER));END_PROPERTYBEGIN_PROPERTY(CICONVIEW_current) MyIconViewItem *item = (MyIconViewItem *)(WIDGET->currentItem()); THIS->item = item; if (item == 0) GB.ReturnNull(); else RETURN_SELF();END_PROPERTYBEGIN_PROPERTY(CICONVIEW_key) MyIconViewItem *item = (MyIconViewItem *)(WIDGET->currentItem()); THIS->item = item; if (item == 0) GB.ReturnNull(); else GB.ReturnString(item->key);END_PROPERTYBEGIN_PROPERTY(CICONVIEW_item) if (THIS->item == 0) GB.ReturnNull(); else RETURN_SELF();END_PROPERTYBEGIN_PROPERTY(CICONVIEW_available) GB.ReturnBoolean(THIS->item != 0);END_PROPERTYBEGIN_METHOD(CICONVIEW_find, GB_INTEGER x; GB_INTEGER y) QPoint p(VARG(x), VARG(y)); MyIconViewItem *item; WIDGET->viewport()->mapFrom(WIDGET, p); item = (MyIconViewItem *)WIDGET->findItem(p); THIS->item = item; GB.ReturnBoolean(THIS->item == 0);END_METHODstatic void set_sorting(void *_object, bool sorted, bool asc){ if (sorted == THIS->sorted && asc == THIS->asc) return; THIS->sorted = sorted; THIS->asc = asc; //qDebug("setSorting(%s, %s)", THIS->sorted ? "true" : "false", THIS->asc ? "true" : "false"); WIDGET->setSorting(THIS->sorted, THIS->asc); if (THIS->sorted) { //qDebug("sort(%s)", THIS->asc ? "true" : "false"); WIDGET->sort(); }}BEGIN_PROPERTY(CICONVIEW_sorted) if (READ_PROPERTY) GB.ReturnBoolean(THIS->sorted); else set_sorting(_object, VPROP(GB_BOOLEAN), THIS->asc);END_PROPERTYBEGIN_PROPERTY(CICONVIEW_ascending) if (READ_PROPERTY) GB.ReturnBoolean(THIS->asc); else set_sorting(_object, THIS->sorted, VPROP(GB_BOOLEAN));END_PROPERTYBEGIN_PROPERTY(CICONVIEW_count) GB.ReturnInteger(WIDGET->count());END_PROPERTYstatic void return_item(void *_object, MyIconViewItem *item){ THIS->item = item; GB.ReturnBoolean(item == 0);}BEGIN_METHOD(CICONVIEW_move_to, GB_STRING key) char *key = GB.ToZeroString(ARG(key)); MyIconViewItem *item = (*THIS->dict)[key]; return_item(THIS, item);END_METHOD
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -