[rkward-cvs] rkward/rkward/misc multistringselector.cpp,NONE,1.1 multistringselector.h,NONE,1.1 Makefile.am,1.7,1.8

Thomas Friedrichsmeier tfry at users.sourceforge.net
Fri Sep 9 23:14:58 UTC 2005


Update of /cvsroot/rkward/rkward/rkward/misc
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv883

Modified Files:
	Makefile.am 
Added Files:
	multistringselector.cpp multistringselector.h 
Log Message:
Adding another convenience widget to misc. Not tested, yet

Index: Makefile.am
===================================================================
RCS file: /cvsroot/rkward/rkward/rkward/misc/Makefile.am,v
retrieving revision 1.7
retrieving revision 1.8
diff -C2 -d -r1.7 -r1.8
*** Makefile.am	8 May 2005 16:54:29 -0000	1.7
--- Makefile.am	9 Sep 2005 23:14:56 -0000	1.8
***************
*** 3,9 ****
  noinst_LIBRARIES =  libmisc.a
  libmisc_a_SOURCES = rkerrordialog.cpp rkmenu.cpp rkspinbox.cpp \
! 	rktogglewidget.cpp getfilenamewidget.cpp rkmenulist.cpp rkobjectlistview.cpp \
! 	rkcanceldialog.cpp xmlhelper.cpp
  noinst_HEADERS = rkerrordialog.h rkmenu.h rkspinbox.h rktogglewidget.h \
! 	getfilenamewidget.h rkmenulist.h rkobjectlistview.h rkcanceldialog.h xmlhelper.h
  
--- 3,10 ----
  noinst_LIBRARIES =  libmisc.a
  libmisc_a_SOURCES = rkerrordialog.cpp rkmenu.cpp rkspinbox.cpp \
! 		rktogglewidget.cpp getfilenamewidget.cpp rkmenulist.cpp rkobjectlistview.cpp \
! 		rkcanceldialog.cpp xmlhelper.cpp multistringselector.cpp
  noinst_HEADERS = rkerrordialog.h rkmenu.h rkspinbox.h rktogglewidget.h \
! 		getfilenamewidget.h rkmenulist.h rkobjectlistview.h rkcanceldialog.h xmlhelper.h \
! 	multistringselector.h
  

--- NEW FILE: multistringselector.h ---
/***************************************************************************
                          multistringselector  -  description
                             -------------------
    begin                : Fir Sep 10 2005
    copyright            : (C) 2005 by Thomas Friedrichsmeier
    email                : tfry at 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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef MULTISTRINGSELECTOR_H
#define MULTISTRINGSELECTOR_H

#include <qwidget.h>
#include <qstringlist.h>
#include <qstring.h>

class QListView;
class QPushButton;

/** This convenience widget allows to select one or more strings (e.g. filenames) and sort them in any order. The function to acutally select a new string to add to the selection is not implemented in this class for more flexibility. Rather, connect to the getNewString () signal and assign the desired QString in a custom slot.

@author Thomas Friedrichsmeier
*/
class MultiStringSelector : public QWidget {
Q_OBJECT
public:
	MultiStringSelector (const QString& label, QWidget* parent = 0);

	~MultiStringSelector ();

/** get list of current strings (in the correct order, of course) */
	QStringList getValues ();
/** set list of strings. Any strings previously selected are discarded */
	void setValues (const QStringList& values);
public slots:
	void addButtonClicked ();
	void removeButtonClicked ();
	void upButtonClicked ();
	void downButtonClicked ();
	void listSelectionChanged ();
private:
	QListView* list_view;
	QPushButton* add_button;
	QPushButton* remove_button;
	QPushButton* up_button;
	QPushButton* down_button;
signals:
/** This signal is triggered, when the "Add"-button is pressed. Connect to this to your custom slot, and change the string. If you don't touch the string or set it to empty, nothing will be added to the list. Of course it does not make much sense to connect multiple slots to this signal, as only the last one called would be effective. */
	void getNewString (QString *string);
};

#endif

--- NEW FILE: multistringselector.cpp ---
/***************************************************************************
                          multistringselector  -  description
                             -------------------
    begin                : Fir Sep 10 2005
    copyright            : (C) 2005 by Thomas Friedrichsmeier
    email                : tfry at 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 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include "multistringselector.h"

#include <qlistview.h>
#include <qpushbutton.h>
#include <qlayout.h>
#include <qlabel.h>

#include <klocale.h>

#include "../rkglobals.h"
#include "../debug.h"

MultiStringSelector::MultiStringSelector (const QString& label, QWidget* parent) : QWidget (parent) {
	RK_TRACE (MISC);

	QHBoxLayout *hbox = new QHBoxLayout (this, RKGlobals::spacingHint ());

	QVBoxLayout *main_box = new QVBoxLayout (hbox, RKGlobals::spacingHint ());
	QVBoxLayout *button_box = new QVBoxLayout (hbox, RKGlobals::spacingHint ());

	QLabel *label_widget = new QLabel (label, this);
	main_box->addWidget (label_widget);

	list_view = new QListView (this);
	list_view->addColumn (i18n ("Filename"));
	list_view->setSelectionMode (QListView::Single);
	list_view->setSorting (-1);
	connect (list_view, SIGNAL (selectionChanged ()), this, SLOT (listSelectionChanged ()));
	main_box->addWidget (list_view);

	add_button = new QPushButton (i18n ("Add"), this);
	connect (add_button, SIGNAL (clicked ()), this, SLOT (addButtonClicked ()));
	button_box->addWidget (add_button);

	remove_button = new QPushButton (i18n ("Remove"), this);
	connect (remove_button, SIGNAL (clicked ()), this, SLOT (removeButtonClicked ()));
	button_box->addWidget (remove_button);

	button_box->addSpacing (10);

	up_button = new QPushButton (i18n ("Up"), this);
	connect (up_button, SIGNAL (clicked ()), this, SLOT (upButtonClicked ()));
	button_box->addWidget (up_button);

	down_button = new QPushButton (i18n ("Down"), this);
	connect (down_button, SIGNAL (clicked ()), this, SLOT (downButtonClicked ()));
	button_box->addWidget (down_button);

	listSelectionChanged ();		// causes remove, up, and down buttons to be disabled (since no item is selected)
}

MultiStringSelector::~MultiStringSelector () {
	RK_TRACE (MISC);

	// child widgets and listviewitems deleted by qt
}

QStringList MultiStringSelector::getValues () {
	RK_TRACE (MISC);

	QStringList list;
	QListViewItem *item = list_view->firstChild ();
	
	while (item) {
		list.append (item->text (0));
		item = item->nextSibling ();
	}

	return list;
}

void MultiStringSelector::setValues (const QStringList& values) {
	RK_TRACE (MISC);

	list_view->clear ();
	for (QStringList::const_iterator it = values.begin (); it != values.end (); ++it) {
		QListViewItem *item = new QListViewItem (list_view, list_view->lastItem ());
		item->setText (0, (*it));
	}
	listSelectionChanged ();
}

void MultiStringSelector::addButtonClicked () {
	RK_TRACE (MISC);

	QString new_string;
	emit (getNewString (&new_string));
	if (!new_string.isEmpty ()) {
		QListViewItem *item = new QListViewItem (list_view, list_view->lastItem ());
		item->setText (0, new_string);
	}
	listSelectionChanged ();		// update button states
}

void MultiStringSelector::removeButtonClicked () {
	RK_TRACE (MISC);

	delete (list_view->selectedItem ());
}

void MultiStringSelector::upButtonClicked () {
	RK_TRACE (MISC);

	QListViewItem *sel = list_view->selectedItem ();
	RK_ASSERT (sel);

	sel->moveItem (sel->itemAbove ());
}

void MultiStringSelector::downButtonClicked () {
	RK_TRACE (MISC);

	QListViewItem *sel = list_view->selectedItem ();
	RK_ASSERT (sel);

	if (sel->nextSibling ()) sel->moveItem (sel->nextSibling ());
}

void MultiStringSelector::listSelectionChanged () {
	RK_TRACE (MISC);

	if (list_view->selectedItem ()) {
		remove_button->setEnabled (true);
		up_button->setEnabled (true);
		down_button->setEnabled (true);
	} else {
		remove_button->setEnabled (false);
		up_button->setEnabled (false);
		down_button->setEnabled (false);
	}
}

#include "multistringselector.moc"





More information about the rkward-tracker mailing list