listventanas.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2005 by Tomeu Borras Riera                              *
00003  *   tborras@conetxia.com                                                  *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
00019  ***************************************************************************/
00020 
00021 #include <QObject>
00022 #include <QPixmap>
00023 #include <QImage>
00024 #include <QPainter>
00025 #include <QVBoxLayout>
00026 
00027 #include <map>
00028 
00029 #include "listventanas.h"
00030 #include "funcaux.h"
00031 
00032 
00034 
00037 QListWidget1::QListWidget1(QWidget * parent) : QListWidget(parent) {
00038     _depura("QListWidget1::QListWidget1", 0);
00039     _depura("END QListWidget1::QListWidget1", 0);
00040 }
00041 
00042 
00044 
00046 QListWidget1::~QListWidget1() {
00047     _depura("QListWidget1::~QListWidget1", 0);
00048     _depura("END QListWidget1::~QListWidget1", 0);
00049 }
00050 
00051 
00053 
00057 QListWidgetItem1::QListWidgetItem1(QListWidget1 *l, QPixmap &p) : QListWidgetItem(l) {
00058     _depura("QListWidgetItem1::QListWidgetItem1", 0);
00059     setIcon(QIcon(p));
00060     m_list = l;
00061     _depura("END QListWidgetItem1::QListWidgetItem1", 0);
00062 }
00063 
00064 
00066 
00068 QListWidgetItem1::~QListWidgetItem1() {
00069     _depura("QListWidget1::~QListWidgetItem1", 0);
00070     _depura("END QListWidget1::~QListWidgetItem1", 0);
00071 }
00072 
00073 
00075 
00078 void QListWidgetItem1::setObject(QObject *m) {
00079     _depura("QListWidgetItem1::setObject", 0);
00080     m_obj = m;
00081     _depura("END QListWidgetItem1::setObject", 0);
00082 }
00083 
00084 
00086 
00089 void QListWidgetItem1::setNombre(QString m) {
00090     _depura("QListWidgetItem1::setNombre", 0);
00091     m_nombre = m;
00092     setText(m);
00093     _depura("END QListWidgetItem1::setNombre", 0);
00094 }
00095 
00096 
00098 
00101 QObject *QListWidgetItem1::object() {
00102     _depura("QListWidgetItem1::object", 0);
00103     _depura("END QListWidgetItem1::object", 0);
00104     return m_obj;
00105 }
00106 
00107 
00109 
00112 QString QListWidgetItem1::nombre() {
00113     _depura("QListWidgetItem1::nombre", 0);
00114     _depura("END QListWidgetItem1::nombre", 0);
00115     return m_nombre;
00116 }
00117 
00118 
00120 
00123 void listventanas::setWorkspace(QWorkspace2 *w) {
00124     _depura("listventanas::setWorkspace", 0);
00125     m_pWorkspace = w;
00126     _depura("END listventanas::setWorkspace", 0);
00127 }
00128 
00129 
00131 
00134 listventanas::listventanas(QWidget *a) : QDockWidget(a) {
00135     _depura("listventanas::listventanas", 0);
00136     m_listBox = new QListWidget1(this);
00137     m_listBox->setIconSize(QSize(32, 32));
00138     m_listBox->setContentsMargins(0, 0, 0, 0);
00139     m_listBox->setSpacing(0);
00140     m_listBox->setWindowTitle(tr("Indexador"));
00141     setWindowTitle(tr("Indexador"));
00142     setFocusPolicy(Qt::StrongFocus);
00143     setWidget(m_listBox);
00144     connect(m_listBox, SIGNAL(itemDoubleClicked(QListWidgetItem *)), this, SLOT(dclicked()));
00145     connect(m_listBox, SIGNAL(itemClicked(QListWidgetItem *)), this, SLOT(clicked()));
00146     _depura("END listventanas::listventanas", 0);
00147 }
00148 
00149 
00151 
00153 void listventanas::dclicked() {
00154     _depura("listventanas::dclicked", 0);
00155     QWidget *widget = (QWidget *)((QListWidgetItem1 *) m_listBox->currentItem())->object();
00156     if (widget != NULL) {
00157         if (widget->isMaximized() == TRUE) {
00158             widget->showNormal();
00159         } else {
00160             widget->showMaximized();
00161         } // end if
00162     } // end if
00163     _depura("END listventanas::dclicked", 0);
00164 }
00165 
00166 
00168 
00170 void listventanas::clicked() {
00171     _depura("listventanas::clicked", 0);
00172     QWidget *widget = (QWidget *)((QListWidgetItem1 *) m_listBox->currentItem())->object();
00173     if (widget != NULL) {
00174         widget->show();
00175         widget->parentWidget()->raise();
00176         m_pWorkspace->setActiveWindow(widget);
00177     } // end if
00178     _depura("END listventanas::clicked", 0);
00179 }
00180 
00181 
00183 
00185 listventanas::~listventanas() {
00186     _depura("listventanas::~listventanas", 0);
00187     delete m_listBox;
00188     _depura("END listventanas::~listventanas", 0);
00189 }
00190 
00191 
00193 
00195 void listventanas::vaciar() {
00196     _depura("listventanas::vaciar", 0);
00198     int i = 0;
00199     while (i < m_listBox->count()) {
00200         QListWidgetItem1 *m = (QListWidgetItem1 *)m_listBox->item(i);
00201         if (((QWidget *)m->object())->testAttribute(Qt::WA_DeleteOnClose)) {
00202             delete m->object();
00203         } else {
00204             i++;
00205         } // end if
00206     } // end while
00207     _depura("END listventanas::vaciar", 0);
00208 }
00209 
00210 
00212 
00215 int listventanas::numVentanas() {
00216     _depura("listventanas::numVentanas", 0);
00217     _depura("END listventanas::numVentanas", 0);
00218     return m_listBox->count();
00219 }
00220 
00221 
00223 
00227 QObject *listventanas::ventana(int index) {
00228     _depura("listventanas::ventana", 0);
00229     QListWidgetItem1 *m = (QListWidgetItem1 *)m_listBox->item(index);
00230     _depura("END listventanas::ventana", 0);
00231     return m->object();
00232 }
00233 
00234 
00236 
00238 void listventanas::vaciarCompleto() {
00239     _depura("listventanas::vaciarCompleto", 0);
00241     int i = 0;
00242     while (i < m_listBox->count()) {
00243         QListWidgetItem1 *m = (QListWidgetItem1 *)m_listBox->item(i);
00244         delete m->object();
00245     } // end while
00246     _depura("END listventanas::vaciarCompleto", 0);
00247 }
00248 
00249 
00253 
00259 int listventanas::meteWindow(QString nombre, QObject *obj, bool compdup) {
00260     _depura("listventanas::meteWindow", 0, nombre);
00261     try {
00262         int i = 0;
00263         while (i < m_listBox->count()) {
00264             QListWidgetItem1 *m = (QListWidgetItem1 *)m_listBox->item(i);
00266             if (m->object() == obj) {
00267                 _depura("listventanas::La ventana ya existe", 0, nombre);
00268                 m->setNombre(nombre);
00269                 return 0;
00270             } // end if
00271 
00273             if (m->nombre() == nombre && compdup) {
00274                 _depura("listventanas::hay una duplicada y la cerramos", 0);
00275                 _depura("listventanas::mostramos la original", 0);
00276                 ((QWidget *)m->object())->hide();
00277                 ((QWidget *)m->object())->show();
00278                 sacaWindow(obj);
00279                 _depura("listventanas::Establecemos la nueva primaria", 0);
00280                 throw -1;
00281             } // end if
00282             i++;
00283         } // end while
00284         if (i >= m_listBox->count()) {
00285             _depura("insercion", 0);
00286             QPixmap icon = ((QWidget *)obj)->windowIcon().pixmap(32, 32);
00287             QListWidgetItem1 *m = new QListWidgetItem1(m_listBox, icon);
00288             m->setObject(obj);
00289             m->setNombre(nombre);
00290         } // end if
00291     } catch (...) {
00292         _depura("listventanas::meteWindow ventana duplicada", 0);
00293         throw -1;
00294     } // end try
00295     _depura("END listventanas::meteWindow", 0);
00296     return 0;
00297 }
00298 
00299 
00301 
00306 int listventanas::seleccionaWindow(QString nombre, QObject *obj) {
00307     _depura("listventanas::seleccionaWindow", 0);
00308     try {
00309         int i = 0;
00310         while (i < m_listBox->count()) {
00311             QListWidgetItem1 *m = (QListWidgetItem1 *)m_listBox->item(i);
00313             if (m->object() == obj) {
00314                 _depura("END listventanas::seleccionaWindow", 0, "Se ha encontrado la ventana" + nombre);
00315                 m_listBox->setCurrentItem(m);
00316                 return 0;
00317             } // end if
00318             i++;
00319         } // end while
00320     } catch (...) {
00321         throw -1;
00322     } // end try
00323     _depura("END listventanas::seleccionaWindow", 0);
00324     return 0;
00325 }
00326 
00327 
00329 
00332 int listventanas::deSeleccionaWindow() {
00333     _depura("listventanas::deSeleccionaWindow", 0);
00334     try {
00335         m_listBox->clearSelection();
00336         return 0;
00337     } catch (...) {
00338         throw -1;
00339     } // end try
00340     _depura("END listventanas::deSeleccionaWindow", 0);
00341     return 0;
00342 }
00343 
00344 
00346 
00349 void listventanas::sacaWindow(QObject *obj) {
00350     _depura("listventanas::sacaWindow", 0);
00352     int i = 0;
00353     while (i < m_listBox->count()) {
00354         QListWidgetItem1 *m = (QListWidgetItem1 *)m_listBox->item(i);
00355         if (m->object() == obj) {
00356             _depura("listventanas::sacaWindow ventana encontrada y vamos a sacarla", 0, m->nombre());
00357             m_listBox->takeItem(i);
00358             delete m;
00359             break;
00360         } // end if
00361         i++;
00362     } // end while
00363     _depura("END listventanas::sacaWindow", 0);
00364 }
00365 
00366 
00368 
00371 void listventanas::cambiaVisible(bool visible) {
00372     _depura("listventanas::cambiaVisible", 0);
00373     if (visible == TRUE) {
00374         this->show();
00375     } else {
00376         this->hide();
00377     } // end if
00378     _depura("END listventanas::cambiaVisible", 0);
00379 }
00380 
00381 
00383 
00385 void listventanas::closeEvent(QCloseEvent *) {
00386     _depura("listventanas::closeEvent", 0);
00387     emit(cambiaEstadoVisible(FALSE));
00388     _depura("END listventanas::closeEvent", 0);
00389 }
00390 

Generated on Sat Dec 15 00:01:21 2007 for BulmaGes by  doxygen 1.5.1