moved kdeaccessibility kdeaddons kdeadmin kdeartwork kdebindings kdeedu kdegames...
[kdeedu.git] / kvoctrain / kvoctrain / queryoption-dialogs / GroupOptPage.cpp
blob22c5fcfe977fd9250ed3b3905d2bd0f0411ca4d3
1 /***************************************************************************
3 $Id$
5 query groups dialog page
7 -----------------------------------------------------------------------
9 begin : Mon Nov 1 13:10:21 1999
11 copyright : (C) 1999-2001 Ewald Arnold
12 (C) 2001 The KDE-EDU team
14 email : kvoctrain@ewald-arnold.de
16 -----------------------------------------------------------------------
18 ***************************************************************************/
20 /***************************************************************************
21 * *
22 * This program is free software; you can redistribute it and/or modify *
23 * it under the terms of the GNU General Public License as published by *
24 * the Free Software Foundation; either version 2 of the License, or *
25 * (at your option) any later version. *
26 * *
27 ***************************************************************************/
29 #include "GroupOptPage.h"
31 #include <qcombobox.h>
32 #include <qlabel.h>
33 #include <qpushbutton.h>
35 #include <klocale.h>
36 #include <kinputdialog.h>
38 GroupOptPage::GroupOptPage
40 vector<PreSetting> preset,
41 QWidget *parent,
42 const char *name
45 GroupOptPageForm( parent, name )
47 connect( ps_del, SIGNAL(clicked()), SLOT(slotDeleteGroup()) );
48 connect( ps_new, SIGNAL(clicked()), SLOT(slotNewGroup()) );
49 connect( ps_recall, SIGNAL(clicked()), SLOT(slotRecallGroup()) );
50 connect( ps_store, SIGNAL(clicked()), SLOT(slotStoreGroup()) );
51 connect( ps_name, SIGNAL(activated(int)), SLOT(slotGroupSelected(int)) );
53 setCaption(i18n("Groups"));
54 l_name->setBuddy(ps_name);
55 for (int i = 0; i < (int) preset.size(); i++)
56 ps_name->insertItem (preset[i].name);
57 updateButtons();
61 void GroupOptPage::initFocus() const
63 ps_name->setFocus();
67 void GroupOptPage::slotGroupSelected(int )
72 void GroupOptPage::slotDeleteGroup()
74 if (ps_name->count() != 0) {
75 emit deleteGroup (ps_name->currentItem());
76 int curr = ps_name->currentItem();
77 ps_name->removeItem(curr);
78 if (curr >= ps_name->count()-1)
79 ps_name->setCurrentItem(ps_name->count()-1);
82 updateButtons();
86 void GroupOptPage::slotNewGroup()
88 bool ok;
89 QString getGroup = KInputDialog::getText(
90 i18n( "Group Description" ), i18n( "Enter group description:" ), QString::null, &ok );
91 if( !ok )
92 return;
93 ps_name->insertItem(getGroup.stripWhiteSpace());
94 emit newGroup(getGroup.stripWhiteSpace());
95 ps_name->setCurrentItem(ps_name->count()-1);
96 emit selectGroup(ps_name->currentItem());
97 updateButtons();
101 void GroupOptPage::slotRecallGroup()
103 if (ps_name->count() != 0)
104 emit selectGroup(ps_name->currentItem());
108 void GroupOptPage::slotStoreGroup()
110 if (ps_name->count() != 0)
111 emit modifyGroup(ps_name->currentItem());
115 void GroupOptPage::updateButtons()
117 ps_del->setEnabled (ps_name->count() > 0);
118 ps_store->setEnabled (ps_name->count() > 0);
119 ps_recall->setEnabled (ps_name->count() > 0);
120 ps_name->setEnabled (ps_name->count() > 0);
124 void GroupOptPage::keyPressEvent( QKeyEvent *e )
126 if (e->state() & AltButton & ControlButton & ShiftButton == 0) {
127 if ( e->key() == Key_Escape )
128 emit reject();
129 else if ( e->key() == Key_Enter
130 ||e->key() == Key_Return)
131 emit accept();
132 else
133 e->ignore();
135 else
136 e->ignore();
139 #include "GroupOptPage.moc"