File indexing completed on 2024-04-28 04:02:32

0001 //
0002 // C++ Implementation: dlgwindows
0003 //
0004 // Description: 
0005 //
0006 /*
0007 Copyright 2004 Vladimir Lazarenko <vlad@lazarenko.net>
0008 
0009 This program is free software; you can redistribute it and/or
0010 modify it under the terms of the GNU General Public License as
0011 published by the Free Software Foundation; either version 2 of 
0012 the License, or (at your option) any later version.
0013 
0014 This program is distributed in the hope that it will be useful,
0015 but WITHOUT ANY WARRANTY; without even the implied warranty of
0016 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0017 GNU General Public License for more details.
0018 
0019 You should have received a copy of the GNU General Public License
0020 along with this program.  If not, see <http://www.gnu.org/licenses/>.
0021 */
0022 
0023 #include "dlgwindows.h"
0024 
0025 #include "cwindowlist.h"
0026 
0027 #include <KLocalizedString>
0028 
0029 #include <QDialogButtonBox>
0030 #include <QLabel>
0031 #include <QGridLayout>
0032 #include <QListWidget>
0033 #include <QPushButton>
0034 #include <QVBoxLayout>
0035 
0036 dlgWindows::dlgWindows(cWindowList *wlist, QWidget *parent) : QDialog(parent)
0037 {
0038   wl = wlist->windowList();
0039   winlist = wlist;
0040   
0041   createDialog();
0042 }
0043 
0044 
0045 dlgWindows::~dlgWindows()
0046 {
0047 }
0048 
0049 void dlgWindows::createDialog()
0050 {
0051   //initial dialog size
0052   setWindowTitle (i18n("Output Windows"));
0053   
0054   //create main dialog's widget
0055   QGridLayout *layout = new QGridLayout (this);
0056 
0057   //create widgets
0058   QLabel *label = new QLabel (i18n ("&List of output windows"), this);
0059   box = new QListWidget (this);
0060   label->setBuddy (box);
0061   
0062   QFrame *buttons = new QFrame (this);
0063   QVBoxLayout *buttonslayout = new QVBoxLayout (buttons);
0064   
0065   btshow = new QPushButton (i18n("&Show"), buttons);
0066   bthide = new QPushButton (i18n("&Hide"), buttons);
0067   btdelete = new QPushButton (i18n("&Delete"), buttons);
0068   
0069   buttonslayout->setSpacing (5);
0070   
0071   buttonslayout->addWidget (btshow);
0072   buttonslayout->addWidget (bthide);
0073   buttonslayout->addWidget (btdelete);
0074   buttonslayout->addStretch (10);
0075 
0076   QDialogButtonBox *dlgbuttons = new QDialogButtonBox (QDialogButtonBox::Close, this);
0077   connect (dlgbuttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
0078   connect (dlgbuttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
0079 
0080   layout->setColumnStretch (0, 10);
0081   layout->setRowStretch (1, 10);
0082   layout->setSpacing (5);
0083 
0084   layout->addWidget (label, 0, 0);
0085   layout->addWidget (box, 1, 0);
0086   layout->addWidget (buttons, 1, 1);
0087   layout->addWidget (dlgbuttons, 2, 0, 1, 2);
0088   
0089   updateMe();
0090   
0091   connect (btshow, &QPushButton::clicked, this, &dlgWindows::wshow);
0092   connect (bthide, &QPushButton::clicked, this, &dlgWindows::whide);
0093   connect (btdelete, &QPushButton::clicked, this, &dlgWindows::remove);
0094 
0095 }
0096 
0097 QSize dlgWindows::sizeHint() const
0098 {
0099   return QSize (500, 400);
0100 }
0101 
0102 void dlgWindows::wshow()
0103 {
0104   if (!box->count()) return;
0105   QString name;
0106   name = box->currentItem()->text();
0107   
0108   if(!winlist->exists(name))
0109     return;
0110   
0111   if(winlist->isShown(name))
0112     return;
0113   
0114   winlist->show(name);
0115 }
0116 
0117 void dlgWindows::whide()
0118 {
0119   if (!box->count()) return;
0120   QString name;
0121   
0122   name = box->currentItem()->text();
0123   
0124   if(!winlist->exists(name))
0125     return;
0126   
0127   if(!winlist->isShown(name))
0128     return;
0129   
0130   winlist->hide(name);
0131 }
0132 
0133 void dlgWindows::remove()
0134 {
0135   if (!box->count()) return;
0136   QString name;
0137   
0138   name = box->currentItem()->text();
0139   
0140   if(!winlist->exists(name))
0141     return;
0142   
0143   winlist->remove(name);
0144   updateMe();
0145 }
0146 
0147 void dlgWindows::updateMe ()
0148 {
0149   //remember old index
0150   int idx = box->currentRow ();
0151 
0152   box->clear ();
0153   box->addItems(winlist->windowList());
0154 
0155   //make one item active, trying to be intelligent...
0156   box->setCurrentRow ((idx == -1) ? 0 : idx);
0157   if ((box->currentRow () == -1) && (idx != -1))
0158     box->setCurrentRow (idx - 1);
0159   if (box->currentRow () == -1)
0160     box->setCurrentRow (0);
0161 }
0162 
0163 #include "moc_dlgwindows.cpp"