From 89d8c2baa9b51d8da8511a54b9962155aa29c4c0 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 1 Feb 2013 17:25:32 -0600 Subject: Fix FTBFS --- kmymoney2/dialogs/krecentfileitem.cpp | 62 --- kmymoney2/dialogs/krecentfileitem.h | 56 --- kmymoney2/dialogs/kselectdatabasedlg.cpp | 232 ---------- kmymoney2/dialogs/kselectdatabasedlg.h | 65 --- kmymoney2/dialogs/kselectdatabasedlgdecl.ui | 250 ----------- kmymoney2/dialogs/kselecttransactionsdlg.cpp | 178 -------- kmymoney2/dialogs/kselecttransactionsdlg.h | 74 ---- kmymoney2/dialogs/kselecttransactionsdlgdecl.ui | 174 -------- kmymoney2/dialogs/tderecentfileitem.cpp | 62 +++ kmymoney2/dialogs/tderecentfileitem.h | 56 +++ kmymoney2/dialogs/tdeselectdatabasedlg.cpp | 232 ++++++++++ kmymoney2/dialogs/tdeselectdatabasedlg.h | 65 +++ kmymoney2/dialogs/tdeselectdatabasedlgdecl.ui | 250 +++++++++++ kmymoney2/dialogs/tdeselecttransactionsdlg.cpp | 178 ++++++++ kmymoney2/dialogs/tdeselecttransactionsdlg.h | 74 ++++ kmymoney2/dialogs/tdeselecttransactionsdlgdecl.ui | 174 ++++++++ kmymoney2/widgets/klistviewsearchline.cpp | 507 ---------------------- kmymoney2/widgets/klistviewsearchline.h | 260 ----------- kmymoney2/widgets/kmymoneychecklistitem.cpp | 151 ------- kmymoney2/widgets/kmymoneychecklistitem.h | 94 ---- kmymoney2/widgets/kmymoneychectdelistitem.cpp | 151 +++++++ kmymoney2/widgets/kmymoneychectdelistitem.h | 94 ++++ kmymoney2/widgets/tdelistviewsearchline.cpp | 507 ++++++++++++++++++++++ kmymoney2/widgets/tdelistviewsearchline.h | 260 +++++++++++ 24 files changed, 2103 insertions(+), 2103 deletions(-) delete mode 100644 kmymoney2/dialogs/krecentfileitem.cpp delete mode 100644 kmymoney2/dialogs/krecentfileitem.h delete mode 100644 kmymoney2/dialogs/kselectdatabasedlg.cpp delete mode 100644 kmymoney2/dialogs/kselectdatabasedlg.h delete mode 100644 kmymoney2/dialogs/kselectdatabasedlgdecl.ui delete mode 100644 kmymoney2/dialogs/kselecttransactionsdlg.cpp delete mode 100644 kmymoney2/dialogs/kselecttransactionsdlg.h delete mode 100644 kmymoney2/dialogs/kselecttransactionsdlgdecl.ui create mode 100644 kmymoney2/dialogs/tderecentfileitem.cpp create mode 100644 kmymoney2/dialogs/tderecentfileitem.h create mode 100644 kmymoney2/dialogs/tdeselectdatabasedlg.cpp create mode 100644 kmymoney2/dialogs/tdeselectdatabasedlg.h create mode 100644 kmymoney2/dialogs/tdeselectdatabasedlgdecl.ui create mode 100644 kmymoney2/dialogs/tdeselecttransactionsdlg.cpp create mode 100644 kmymoney2/dialogs/tdeselecttransactionsdlg.h create mode 100644 kmymoney2/dialogs/tdeselecttransactionsdlgdecl.ui delete mode 100644 kmymoney2/widgets/klistviewsearchline.cpp delete mode 100644 kmymoney2/widgets/klistviewsearchline.h delete mode 100644 kmymoney2/widgets/kmymoneychecklistitem.cpp delete mode 100644 kmymoney2/widgets/kmymoneychecklistitem.h create mode 100644 kmymoney2/widgets/kmymoneychectdelistitem.cpp create mode 100644 kmymoney2/widgets/kmymoneychectdelistitem.h create mode 100644 kmymoney2/widgets/tdelistviewsearchline.cpp create mode 100644 kmymoney2/widgets/tdelistviewsearchline.h diff --git a/kmymoney2/dialogs/krecentfileitem.cpp b/kmymoney2/dialogs/krecentfileitem.cpp deleted file mode 100644 index 495d81f..0000000 --- a/kmymoney2/dialogs/krecentfileitem.cpp +++ /dev/null @@ -1,62 +0,0 @@ -/*************************************************************************** - krecentfileitem.cpp - description - ------------------- - begin : Wed Jul 30 2003 - copyright : (C) 2000-2003 by Michael Edwardes - email : mte@users.sourceforge.net - Javier Campos Morales - Felix Rodriguez - John C - Thomas Baumgart - Kevin Tambascio - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -// ---------------------------------------------------------------------------- -// QT Includes - -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes - -// ---------------------------------------------------------------------------- -// Project Includes - - -#include "krecentfileitem.h" - -TDERecentFileItem::TDERecentFileItem(const TQString& url, TQIconView* parent, const TQString& text, const TQPixmap& icon) - : TQIconViewItem(parent, text, icon), - m_url(url), - m_parent(parent) -{ - TQToolTip::add(parent, rect(), url); - // avoid moving this item around - setDragEnabled(false); -} - -TDERecentFileItem::~TDERecentFileItem() -{ -} - -bool TDERecentFileItem::move( int x, int y ) -{ - TQRect r = rect(); - TQToolTip::remove(m_parent, rect()); - r.moveTopLeft(TQPoint(x,y)); - TQToolTip::add(m_parent, r, m_url); - return TQIconViewItem::move(x,y); -} - diff --git a/kmymoney2/dialogs/krecentfileitem.h b/kmymoney2/dialogs/krecentfileitem.h deleted file mode 100644 index bc89c48..0000000 --- a/kmymoney2/dialogs/krecentfileitem.h +++ /dev/null @@ -1,56 +0,0 @@ -/*************************************************************************** - krecentfileitem.h - description - ------------------- - begin : Wed Jul 30 2003 - copyright : (C) 2000-2003 by Michael Edwardes - email : mte@users.sourceforge.net - Javier Campos Morales - Felix Rodriguez - John C - Thomas Baumgart - Kevin Tambascio - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 KRECENTFILEITEM_H -#define KRECENTFILEITEM_H - -// ---------------------------------------------------------------------------- -// QT Includes -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes -#include - -// ---------------------------------------------------------------------------- -// Project Includes - - - -/** - * @author Michael Edwardes - */ - -class TDERecentFileItem : public TQIconViewItem { -public: - TDERecentFileItem(const TQString& url, TQIconView* parent, const TQString& text, const TQPixmap& icon); - ~TDERecentFileItem(); - TQString fileURL(void) const { return m_url; } - - bool move( int x, int y ); - -private: - TQString m_url; - TQWidget* m_parent; -}; - -#endif diff --git a/kmymoney2/dialogs/kselectdatabasedlg.cpp b/kmymoney2/dialogs/kselectdatabasedlg.cpp deleted file mode 100644 index 607abbc..0000000 --- a/kmymoney2/dialogs/kselectdatabasedlg.cpp +++ /dev/null @@ -1,232 +0,0 @@ -/*************************************************************************** - kselectdatabasedlg.cpp - ------------------- - copyright : (C) 2005 by Tony Bloomfield - author : Tony Bloomfield - email : tonybloom@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 -#include -#include - -// ---------------------------------------------------------------------------- -// QT Includes - -#include -#include -#include -#include -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes - -#include -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -#include "kselectdatabasedlg.h" - -TDESelectDatabaseDlg::TDESelectDatabaseDlg(TQWidget *parent, const char *name) - : TDESelectDatabaseDlgDecl(parent, name) { - listDrivers->clear(); - // list drivers supported by KMM - TQMap map = m_map.driverMap(); - // list drivers installed on system - TQStringList list = TQSqlDatabase::drivers(); - if (list.count() == 0) { - KMessageBox::error (0, i18n("There are no TQt SQL drivers installed in your system.\n" - "Please consult documentation for your distro, or visit the TQt web site (www.trolltech.com)" - " and search for SQL drivers."), - ""); - setError(); - } else { - TQStringList::Iterator it = list.begin(); - while(it != list.end()) { - TQString dname = *it; - if (map.keys().contains(dname)) { // only display if driver is supported - dname = dname + " - " + map[dname]; - listDrivers->insertItem (dname); - } - it++; - } - textDbName->setText ("KMyMoney"); - textHostName->setText ("localhost"); - textUserName->setText(""); - struct passwd * pwd = getpwuid(geteuid()); - if (pwd != 0) - textUserName->setText (TQString(pwd->pw_name)); - textPassword->setText (""); - m_requiredFields = new kMandatoryFieldGroup(TQT_TQOBJECT(this)); - m_requiredFields->setOkButton(buttonOK); - m_requiredFields->add(listDrivers); - m_requiredFields->add(textDbName); - connect (listDrivers, TQT_SIGNAL(clicked(TQListBoxItem *)), - this, TQT_SLOT(slotDriverSelected(TQListBoxItem *))); - connect (buttonSQL, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotGenerateSQL())); - connect (buttonOK, TQT_SIGNAL(clicked()), this, TQT_SLOT(accept())); - checkPreLoad->setChecked(false); - buttonSQL->setEnabled(true); - } - connect (buttonHelp, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotHelp())); - // ensure a driver gets selected; pre-select if only one - listDrivers->clearSelection(); - if (listDrivers->count() == 1) { - listDrivers->setSelected(0, true); - slotDriverSelected(listDrivers->item(0)); - } -} - -TDESelectDatabaseDlg::TDESelectDatabaseDlg(KURL openURL, TQWidget *parent, const char *name) - : TDESelectDatabaseDlgDecl(parent, name) { - // here we are re-opening a database from a URL - // probably taken from the last-used or recent file list - listDrivers->clear(); - // check that the SQL driver is still available - TQString driverName = openURL.queryItem("driver"); - // list drivers installed on system - TQStringList list = TQSqlDatabase::drivers(); - // list drivers supported by KMM - TQMap map = m_map.driverMap(); - if (!list.contains(driverName)) { - KMessageBox::error (0, i18n("TQt SQL driver %1 is no longer installed on your system").arg(driverName), - ""); - setError(); - } else if (!map.contains(driverName)) { - KMessageBox::error (0, i18n("TQt SQL driver %1 is not suported").arg(driverName), - ""); - setError(); - } else { - // fill in the fixed data from the URL - listDrivers->insertItem (TQString(driverName + " - " + map[driverName])); - listDrivers->setSelected(0,true); - TQString dbName = openURL.path().right(openURL.path().length() - 1); // remove separator slash - textDbName->setText (dbName); - textHostName->setText (openURL.host()); - textUserName->setText(openURL.user()); - // disable all but the password field, coz that's why we're here - textDbName->setEnabled(false); - listDrivers->setEnabled(false); - textHostName->setEnabled(false); - textUserName->setEnabled(false); - textPassword->setEnabled(true); - textPassword->setFocus(); - buttonSQL->setEnabled(false); - // set password as required - m_requiredFields = new kMandatoryFieldGroup(TQT_TQOBJECT(this)); - m_requiredFields->add(textPassword); - m_requiredFields->setOkButton(buttonOK); - - connect (buttonOK, TQT_SIGNAL(clicked()), this, TQT_SLOT(accept())); - checkPreLoad->setChecked(false); - } - connect (buttonHelp, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotHelp())); - -} - -TDESelectDatabaseDlg::~TDESelectDatabaseDlg() { - if (m_requiredFields != 0) delete m_requiredFields; -} - -void TDESelectDatabaseDlg::setMode (int openMode) { - m_mode = openMode; - checkPreLoad->setEnabled (openMode == IO_ReadWrite); -} - -const KURL TDESelectDatabaseDlg::selectedURL() { - KURL url; - url.setProtocol("sql"); - url.setUser(textUserName->text()); - url.setPass(textPassword->text()); - url.setHost(textHostName->text()); - url.setPath("/" + textDbName->text()); - TQString qs = TQString("driver=%1") - .arg(listDrivers->currentText().section (' ', 0, 0)); - if (checkPreLoad->isChecked()) qs.append("&options=loadAll"); - if (!textPassword->text().isEmpty()) qs.append("&secure=yes"); - url.setQuery(qs); - return (url); -} - -void TDESelectDatabaseDlg::slotDriverSelected (TQListBoxItem *driver) { - databaseTypeE dbType = m_map.driverToType(driver->text().section(' ', 0, 0)); - if (!m_map.isTested(dbType)) { - int rc = KMessageBox::warningContinueCancel (0, - i18n("TQt SQL driver %1 has not been fully tested in a KMyMoney environment. Please make sure you have adequate backups of your data. Please report any problems to the developer mailing list at kmymoney2-developer@lists.sourceforge.net") - .arg(driver->text()), - ""); - if (rc == KMessageBox::Cancel) { - listDrivers->clearSelection(); - return; - } - } - - if (dbType == Sqlite3){ - TQString dbName = TQFileDialog::getOpenFileName( - "", - i18n("SQLite files (*.sql);; All files (*.*)"), - this, - "", - i18n("Select SQLite file")); - if (dbName.isNull()) { - listDrivers->setSelected(driver, false); - return; - } else { - textDbName->setText(dbName); - } - // sql databases do not react to host/user/password; file system permissions must be used - textHostName->setEnabled (false); - textUserName->setEnabled (false); - textPassword->setEnabled(false); - } else { - textUserName->setEnabled (true); // but not host - textHostName->setEnabled (true); - textPassword->setEnabled(true); - } -} - -void TDESelectDatabaseDlg::slotGenerateSQL () { - TQString fileName = TQFileDialog::getSaveFileName( - "", - i18n("All files (*.*)"), - this, - "", - i18n("Select output file")); - if (fileName == "") return; - TQFile out(fileName); - if (!out.open(IO_WriteOnly)) return; - TQTextStream s(&out); - MyMoneyDbDef db; - s << db.generateSQL(listDrivers->currentText().section (' ', 0, 0)); - out.close(); -} - -void TDESelectDatabaseDlg::slotHelp(void) { - kapp->invokeHelp("details.database.selectdatabase"); -} - -void TDESelectDatabaseDlg::setError() { - buttonOK->setEnabled(false); - buttonSQL->setEnabled(false); - m_requiredFields = 0; -} - -#include "kselectdatabasedlg.moc" diff --git a/kmymoney2/dialogs/kselectdatabasedlg.h b/kmymoney2/dialogs/kselectdatabasedlg.h deleted file mode 100644 index 4fe2809..0000000 --- a/kmymoney2/dialogs/kselectdatabasedlg.h +++ /dev/null @@ -1,65 +0,0 @@ -/*************************************************************************** - kselectdatabase.h - ------------------- - copyright : (C) 2005 by Tony Bloomfield - author : Tony Bloomfield - email : tonybloom@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 KSELECTDATABASEDLG_H -#define KSELECTDATABASEDLG_H - -// ---------------------------------------------------------------------------- -// QT Includes -#include -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes -#include - -// ---------------------------------------------------------------------------- -// Project Includes -#include "kselectdatabasedlgdecl.h" -#include "../mymoney/storage/mymoneystoragesql.h" -#include "kmymoney/kguiutils.h" - -class TDESelectDatabaseDlg : public TDESelectDatabaseDlgDecl -{ -Q_OBJECT - -public: - TDESelectDatabaseDlg(TQWidget *parent = 0, const char *name = 0); - TDESelectDatabaseDlg(KURL openURL, TQWidget *parent = 0, const char *name = 0); - ~TDESelectDatabaseDlg(); - /** Set the mode of this dialog - * @param - openMode (IO_ReadWrite = open database; IO_WriteOnly = saveas database) - **/ - void setMode(int openMode); - /** Return URL of database - * @return - pseudo-URL of database selected by user - **/ - const KURL selectedURL(); - -public slots: - void slotDriverSelected(TQListBoxItem *driver); - void slotHelp(); - void slotGenerateSQL(); -private: - void setError(); - int m_mode; - MyMoneyDbDrivers m_map; - kMandatoryFieldGroup* m_requiredFields; -}; - -#endif diff --git a/kmymoney2/dialogs/kselectdatabasedlgdecl.ui b/kmymoney2/dialogs/kselectdatabasedlgdecl.ui deleted file mode 100644 index 5e756a7..0000000 --- a/kmymoney2/dialogs/kselectdatabasedlgdecl.ui +++ /dev/null @@ -1,250 +0,0 @@ - -TDESelectDatabaseDlgDecl - - - TDESelectDatabaseDlgDecl - - - - 0 - 0 - 449 - 640 - - - - KMyMoney - Select Database - - - - unnamed - - - - groupBox6 - - - CAUTION! - - - - unnamed - - - - kActiveLabel1 - - - - 10 - 1 - - - - NoFocus - - - <font color="#ff2727">This software is still in an experimental stage, and there are still some known response time problems. Please be patient; we are working on them. -As always, please make sure you have adequate backups of your data.</font> - - - - - - - groupBox1 - - - Database Type - - - - unnamed - - - - listDrivers - - - - - - - groupBox2 - - - Database Name - - - - unnamed - - - - textDbName - - - - - - - groupBox3 - - - Host Name - - - - unnamed - - - - textHostName - - - - - - - groupBox4 - - - User Name - - - - unnamed - - - - textUserName - - - - - - - groupBoxPassword - - - Password - - - - unnamed - - - - textPassword - - - Password - - - - - - - checkPreLoad - - - Preload &all data - - - - - layout3 - - - - unnamed - - - - buttonHelp - - - Help - - - - - spacer3 - - - Horizontal - - - Expanding - - - - 20 - 20 - - - - - - buttonSQL - - - &Generate SQL - - - - - spacer2 - - - Horizontal - - - Expanding - - - - 31 - 20 - - - - - - buttonOK - - - OK - - - true - - - - - buttonCancel - - - Ca&ncel - - - - - - - - - buttonOK - released() - TDESelectDatabaseDlgDecl - accept() - - - buttonCancel - released() - TDESelectDatabaseDlgDecl - reject() - - - - diff --git a/kmymoney2/dialogs/kselecttransactionsdlg.cpp b/kmymoney2/dialogs/kselecttransactionsdlg.cpp deleted file mode 100644 index 51968f1..0000000 --- a/kmymoney2/dialogs/kselecttransactionsdlg.cpp +++ /dev/null @@ -1,178 +0,0 @@ -/*************************************************************************** - kselecttransactionsdlg.cpp - ------------------- - begin : Wed May 16 2007 - copyright : (C) 2007 by Thomas Baumgart - email : ipwizard@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. * - * * - ***************************************************************************/ - -// ---------------------------------------------------------------------------- -// QT Includes - -// ---------------------------------------------------------------------------- -// KDE Includes - -#include -#include -#include -#include -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -#include -#include -#include - -#include "kmergetransactionsdlg.h" - -TDESelectTransactionsDlg::TDESelectTransactionsDlg(const MyMoneyAccount& _account, TQWidget* parent, const char* name) : - TDESelectTransactionsDlgDecl(parent, name), - m_account(_account) -{ - // setup descriptive texts - setCaption(i18n("Select Transaction")); - m_description->setText(i18n("Select a transaction and press the OK button or use Cancel to select none.")); - - // clear current register contents - m_register->clear(); - - // no selection possible - m_register->setSelectionMode(TQTable::Single); - - // setup header font - TQFont font = KMyMoneyGlobalSettings::listHeaderFont(); - TQFontMetrics fm( font ); - int height = fm.lineSpacing()+6; - m_register->horizontalHeader()->setMinimumHeight(height); - m_register->horizontalHeader()->setMaximumHeight(height); - m_register->horizontalHeader()->setFont(font); - - // setup cell font - font = KMyMoneyGlobalSettings::listCellFont(); - m_register->setFont(font); - - // ... setup the register columns ... - m_register->setupRegister(m_account); - - // setup buttons - m_helpButton->setGuiItem(KStdGuiItem::help()); - buttonOk->setGuiItem(KStdGuiItem::ok()); - buttonCancel->setGuiItem(KStdGuiItem::cancel()); - - // default is to need at least one transaction selected - buttonOk->setDisabled(true); - - // catch some events from the register - m_register->installEventFilter(this); - - connect(m_register, TQT_SIGNAL(selectionChanged(const KMyMoneyRegister::SelectedTransactions&)), this, TQT_SLOT(slotEnableOk(const KMyMoneyRegister::SelectedTransactions&))); - connect(m_register, TQT_SIGNAL(editTransaction()), this, TQT_SLOT(accept())); - - connect(m_helpButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotHelp())); -} - -void TDESelectTransactionsDlg::slotEnableOk(const KMyMoneyRegister::SelectedTransactions& list) -{ - buttonOk->setEnabled(list.count() != 0); -} - -void TDESelectTransactionsDlg::addTransaction(const MyMoneyTransaction& t) -{ - TQValueList::const_iterator it_s; - for(it_s = t.splits().begin(); it_s != t.splits().end(); ++it_s) { - if((*it_s).accountId() == m_account.id()) { - KMyMoneyRegister::Transaction* tr = KMyMoneyRegister::Register::transactionFactory(m_register, t, (*it_s), 0); - // force full detail display - tr->setNumRowsRegister(tr->numRowsRegister(true)); - break; - } - } -} - -int TDESelectTransactionsDlg::exec(void) -{ - m_register->updateRegister(true); - m_register->updateContents(); - - m_register->setFocus(); - - return TDESelectTransactionsDlgDecl::exec(); -} - -void TDESelectTransactionsDlg::slotHelp(void) -{ - // kapp->invokeHelp("details.ledgers.match"); -} - -void TDESelectTransactionsDlg::show(void) -{ - TDESelectTransactionsDlgDecl::show(); - m_register->resize(KMyMoneyRegister::DetailColumn); -} - -void TDESelectTransactionsDlg::resizeEvent(TQResizeEvent* ev) -{ - // don't forget the resizer - TDESelectTransactionsDlgDecl::resizeEvent(ev); - - // resize the register - m_register->resize(KMyMoneyRegister::DetailColumn); -} - -MyMoneyTransaction TDESelectTransactionsDlg::transaction(void) const -{ - MyMoneyTransaction t; - - TQValueList list; - list = m_register->selectedItems(); - if(list.count()) { - KMyMoneyRegister::Transaction* _t = dynamic_cast(list[0]); - if(_t) - t = _t->transaction(); - } - return t; -} - -bool TDESelectTransactionsDlg::eventFilter(TQObject* o, TQEvent* e) -{ - bool rc = false; - TQKeyEvent* k; - - if(TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_register)) { - switch(e->type()) { - case TQEvent::KeyPress: - k = dynamic_cast(e); - if((k->state() & TQt::KeyButtonMask) == 0) { - switch(k->key()) { - case TQt::Key_Return: - case TQt::Key_Enter: - if(buttonOk->isEnabled()) { - accept(); - rc = true; - } - // tricky fall through here - default: - break; - } - } - // tricky fall through here - default: - break; - } - } - return rc; -} - -#include "kselecttransactionsdlg.moc" -// vim:cin:si:ai:et:ts=2:sw=2: diff --git a/kmymoney2/dialogs/kselecttransactionsdlg.h b/kmymoney2/dialogs/kselecttransactionsdlg.h deleted file mode 100644 index 4eeaea2..0000000 --- a/kmymoney2/dialogs/kselecttransactionsdlg.h +++ /dev/null @@ -1,74 +0,0 @@ -/*************************************************************************** - kselecttransactionsdlg.h - ------------------- - begin : Wed May 16 2007 - copyright : (C) 2007 by Thomas Baumgart - email : ipwizard@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 KSELECTTRANSACTIONSDLG_H -#define KSELECTTRANSACTIONSDLG_H - -// ---------------------------------------------------------------------------- -// QT Includes - -class TQResizeEvent; - -// ---------------------------------------------------------------------------- -// KDE Includes - -#include - -// ---------------------------------------------------------------------------- -// Project Includes - -#include -#include - -#include "../dialogs/kselecttransactionsdlgdecl.h" - -class TDESelectTransactionsDlg: public TDESelectTransactionsDlgDecl -{ - Q_OBJECT - -public: - TDESelectTransactionsDlg(const MyMoneyAccount& account, TQWidget* parent = 0, const char* name = 0); - - /** - * Adds the transaction @a t to the dialog - */ - void addTransaction(const MyMoneyTransaction& t); - int exec(void); - void show(void); - - MyMoneyTransaction transaction(void) const; - - bool eventFilter(TQObject* o, TQEvent* e); - -public slots: - virtual void slotHelp(); - -protected slots: - void slotEnableOk(const KMyMoneyRegister::SelectedTransactions& list); - -protected: - void resizeEvent(TQResizeEvent* ev); - -private: - /** - * The account in which the transactions are displayed - */ - MyMoneyAccount m_account; -}; - -#endif // KMERGETRANSACTIONSDLG_H -// vim:cin:si:ai:et:ts=2:sw=2: diff --git a/kmymoney2/dialogs/kselecttransactionsdlgdecl.ui b/kmymoney2/dialogs/kselecttransactionsdlgdecl.ui deleted file mode 100644 index 24bc6f0..0000000 --- a/kmymoney2/dialogs/kselecttransactionsdlgdecl.ui +++ /dev/null @@ -1,174 +0,0 @@ - -TDESelectTransactionsDlgDecl - - - TDESelectTransactionsDlgDecl - - - - 0 - 0 - 794 - 456 - - - - xxx - - - true - - - - unnamed - - - - m_description - - - NoFocus - - - xxx - - - - - - Security - - - - - Details - - - - - C - - - - - Payment - - - - - Deposit - - - - - Quantity - - - - - Price - - - - - Value - - - - - Balance - - - - m_register - - - - 7 - 7 - 0 - 3 - - - - 0 - - - 12 - - - - - layout2 - - - - unnamed - - - - m_helpButton - - - Help - - - - - Horizontal Spacing2 - - - Horizontal - - - Expanding - - - - 430 - 20 - - - - - - buttonOk - - - OK - - - true - - - true - - - - - buttonCancel - - - Cancel - - - - - - - - - buttonOk - clicked() - TDESelectTransactionsDlgDecl - accept() - - - buttonCancel - clicked() - TDESelectTransactionsDlgDecl - reject() - - - - diff --git a/kmymoney2/dialogs/tderecentfileitem.cpp b/kmymoney2/dialogs/tderecentfileitem.cpp new file mode 100644 index 0000000..495d81f --- /dev/null +++ b/kmymoney2/dialogs/tderecentfileitem.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + krecentfileitem.cpp - description + ------------------- + begin : Wed Jul 30 2003 + copyright : (C) 2000-2003 by Michael Edwardes + email : mte@users.sourceforge.net + Javier Campos Morales + Felix Rodriguez + John C + Thomas Baumgart + Kevin Tambascio + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + + +#include "krecentfileitem.h" + +TDERecentFileItem::TDERecentFileItem(const TQString& url, TQIconView* parent, const TQString& text, const TQPixmap& icon) + : TQIconViewItem(parent, text, icon), + m_url(url), + m_parent(parent) +{ + TQToolTip::add(parent, rect(), url); + // avoid moving this item around + setDragEnabled(false); +} + +TDERecentFileItem::~TDERecentFileItem() +{ +} + +bool TDERecentFileItem::move( int x, int y ) +{ + TQRect r = rect(); + TQToolTip::remove(m_parent, rect()); + r.moveTopLeft(TQPoint(x,y)); + TQToolTip::add(m_parent, r, m_url); + return TQIconViewItem::move(x,y); +} + diff --git a/kmymoney2/dialogs/tderecentfileitem.h b/kmymoney2/dialogs/tderecentfileitem.h new file mode 100644 index 0000000..bc89c48 --- /dev/null +++ b/kmymoney2/dialogs/tderecentfileitem.h @@ -0,0 +1,56 @@ +/*************************************************************************** + krecentfileitem.h - description + ------------------- + begin : Wed Jul 30 2003 + copyright : (C) 2000-2003 by Michael Edwardes + email : mte@users.sourceforge.net + Javier Campos Morales + Felix Rodriguez + John C + Thomas Baumgart + Kevin Tambascio + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KRECENTFILEITEM_H +#define KRECENTFILEITEM_H + +// ---------------------------------------------------------------------------- +// QT Includes +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes +#include + +// ---------------------------------------------------------------------------- +// Project Includes + + + +/** + * @author Michael Edwardes + */ + +class TDERecentFileItem : public TQIconViewItem { +public: + TDERecentFileItem(const TQString& url, TQIconView* parent, const TQString& text, const TQPixmap& icon); + ~TDERecentFileItem(); + TQString fileURL(void) const { return m_url; } + + bool move( int x, int y ); + +private: + TQString m_url; + TQWidget* m_parent; +}; + +#endif diff --git a/kmymoney2/dialogs/tdeselectdatabasedlg.cpp b/kmymoney2/dialogs/tdeselectdatabasedlg.cpp new file mode 100644 index 0000000..607abbc --- /dev/null +++ b/kmymoney2/dialogs/tdeselectdatabasedlg.cpp @@ -0,0 +1,232 @@ +/*************************************************************************** + kselectdatabasedlg.cpp + ------------------- + copyright : (C) 2005 by Tony Bloomfield + author : Tony Bloomfield + email : tonybloom@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 +#include +#include + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include +#include +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kselectdatabasedlg.h" + +TDESelectDatabaseDlg::TDESelectDatabaseDlg(TQWidget *parent, const char *name) + : TDESelectDatabaseDlgDecl(parent, name) { + listDrivers->clear(); + // list drivers supported by KMM + TQMap map = m_map.driverMap(); + // list drivers installed on system + TQStringList list = TQSqlDatabase::drivers(); + if (list.count() == 0) { + KMessageBox::error (0, i18n("There are no TQt SQL drivers installed in your system.\n" + "Please consult documentation for your distro, or visit the TQt web site (www.trolltech.com)" + " and search for SQL drivers."), + ""); + setError(); + } else { + TQStringList::Iterator it = list.begin(); + while(it != list.end()) { + TQString dname = *it; + if (map.keys().contains(dname)) { // only display if driver is supported + dname = dname + " - " + map[dname]; + listDrivers->insertItem (dname); + } + it++; + } + textDbName->setText ("KMyMoney"); + textHostName->setText ("localhost"); + textUserName->setText(""); + struct passwd * pwd = getpwuid(geteuid()); + if (pwd != 0) + textUserName->setText (TQString(pwd->pw_name)); + textPassword->setText (""); + m_requiredFields = new kMandatoryFieldGroup(TQT_TQOBJECT(this)); + m_requiredFields->setOkButton(buttonOK); + m_requiredFields->add(listDrivers); + m_requiredFields->add(textDbName); + connect (listDrivers, TQT_SIGNAL(clicked(TQListBoxItem *)), + this, TQT_SLOT(slotDriverSelected(TQListBoxItem *))); + connect (buttonSQL, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotGenerateSQL())); + connect (buttonOK, TQT_SIGNAL(clicked()), this, TQT_SLOT(accept())); + checkPreLoad->setChecked(false); + buttonSQL->setEnabled(true); + } + connect (buttonHelp, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotHelp())); + // ensure a driver gets selected; pre-select if only one + listDrivers->clearSelection(); + if (listDrivers->count() == 1) { + listDrivers->setSelected(0, true); + slotDriverSelected(listDrivers->item(0)); + } +} + +TDESelectDatabaseDlg::TDESelectDatabaseDlg(KURL openURL, TQWidget *parent, const char *name) + : TDESelectDatabaseDlgDecl(parent, name) { + // here we are re-opening a database from a URL + // probably taken from the last-used or recent file list + listDrivers->clear(); + // check that the SQL driver is still available + TQString driverName = openURL.queryItem("driver"); + // list drivers installed on system + TQStringList list = TQSqlDatabase::drivers(); + // list drivers supported by KMM + TQMap map = m_map.driverMap(); + if (!list.contains(driverName)) { + KMessageBox::error (0, i18n("TQt SQL driver %1 is no longer installed on your system").arg(driverName), + ""); + setError(); + } else if (!map.contains(driverName)) { + KMessageBox::error (0, i18n("TQt SQL driver %1 is not suported").arg(driverName), + ""); + setError(); + } else { + // fill in the fixed data from the URL + listDrivers->insertItem (TQString(driverName + " - " + map[driverName])); + listDrivers->setSelected(0,true); + TQString dbName = openURL.path().right(openURL.path().length() - 1); // remove separator slash + textDbName->setText (dbName); + textHostName->setText (openURL.host()); + textUserName->setText(openURL.user()); + // disable all but the password field, coz that's why we're here + textDbName->setEnabled(false); + listDrivers->setEnabled(false); + textHostName->setEnabled(false); + textUserName->setEnabled(false); + textPassword->setEnabled(true); + textPassword->setFocus(); + buttonSQL->setEnabled(false); + // set password as required + m_requiredFields = new kMandatoryFieldGroup(TQT_TQOBJECT(this)); + m_requiredFields->add(textPassword); + m_requiredFields->setOkButton(buttonOK); + + connect (buttonOK, TQT_SIGNAL(clicked()), this, TQT_SLOT(accept())); + checkPreLoad->setChecked(false); + } + connect (buttonHelp, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotHelp())); + +} + +TDESelectDatabaseDlg::~TDESelectDatabaseDlg() { + if (m_requiredFields != 0) delete m_requiredFields; +} + +void TDESelectDatabaseDlg::setMode (int openMode) { + m_mode = openMode; + checkPreLoad->setEnabled (openMode == IO_ReadWrite); +} + +const KURL TDESelectDatabaseDlg::selectedURL() { + KURL url; + url.setProtocol("sql"); + url.setUser(textUserName->text()); + url.setPass(textPassword->text()); + url.setHost(textHostName->text()); + url.setPath("/" + textDbName->text()); + TQString qs = TQString("driver=%1") + .arg(listDrivers->currentText().section (' ', 0, 0)); + if (checkPreLoad->isChecked()) qs.append("&options=loadAll"); + if (!textPassword->text().isEmpty()) qs.append("&secure=yes"); + url.setQuery(qs); + return (url); +} + +void TDESelectDatabaseDlg::slotDriverSelected (TQListBoxItem *driver) { + databaseTypeE dbType = m_map.driverToType(driver->text().section(' ', 0, 0)); + if (!m_map.isTested(dbType)) { + int rc = KMessageBox::warningContinueCancel (0, + i18n("TQt SQL driver %1 has not been fully tested in a KMyMoney environment. Please make sure you have adequate backups of your data. Please report any problems to the developer mailing list at kmymoney2-developer@lists.sourceforge.net") + .arg(driver->text()), + ""); + if (rc == KMessageBox::Cancel) { + listDrivers->clearSelection(); + return; + } + } + + if (dbType == Sqlite3){ + TQString dbName = TQFileDialog::getOpenFileName( + "", + i18n("SQLite files (*.sql);; All files (*.*)"), + this, + "", + i18n("Select SQLite file")); + if (dbName.isNull()) { + listDrivers->setSelected(driver, false); + return; + } else { + textDbName->setText(dbName); + } + // sql databases do not react to host/user/password; file system permissions must be used + textHostName->setEnabled (false); + textUserName->setEnabled (false); + textPassword->setEnabled(false); + } else { + textUserName->setEnabled (true); // but not host + textHostName->setEnabled (true); + textPassword->setEnabled(true); + } +} + +void TDESelectDatabaseDlg::slotGenerateSQL () { + TQString fileName = TQFileDialog::getSaveFileName( + "", + i18n("All files (*.*)"), + this, + "", + i18n("Select output file")); + if (fileName == "") return; + TQFile out(fileName); + if (!out.open(IO_WriteOnly)) return; + TQTextStream s(&out); + MyMoneyDbDef db; + s << db.generateSQL(listDrivers->currentText().section (' ', 0, 0)); + out.close(); +} + +void TDESelectDatabaseDlg::slotHelp(void) { + kapp->invokeHelp("details.database.selectdatabase"); +} + +void TDESelectDatabaseDlg::setError() { + buttonOK->setEnabled(false); + buttonSQL->setEnabled(false); + m_requiredFields = 0; +} + +#include "kselectdatabasedlg.moc" diff --git a/kmymoney2/dialogs/tdeselectdatabasedlg.h b/kmymoney2/dialogs/tdeselectdatabasedlg.h new file mode 100644 index 0000000..4fe2809 --- /dev/null +++ b/kmymoney2/dialogs/tdeselectdatabasedlg.h @@ -0,0 +1,65 @@ +/*************************************************************************** + kselectdatabase.h + ------------------- + copyright : (C) 2005 by Tony Bloomfield + author : Tony Bloomfield + email : tonybloom@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 KSELECTDATABASEDLG_H +#define KSELECTDATABASEDLG_H + +// ---------------------------------------------------------------------------- +// QT Includes +#include +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes +#include + +// ---------------------------------------------------------------------------- +// Project Includes +#include "kselectdatabasedlgdecl.h" +#include "../mymoney/storage/mymoneystoragesql.h" +#include "kmymoney/kguiutils.h" + +class TDESelectDatabaseDlg : public TDESelectDatabaseDlgDecl +{ +Q_OBJECT + +public: + TDESelectDatabaseDlg(TQWidget *parent = 0, const char *name = 0); + TDESelectDatabaseDlg(KURL openURL, TQWidget *parent = 0, const char *name = 0); + ~TDESelectDatabaseDlg(); + /** Set the mode of this dialog + * @param - openMode (IO_ReadWrite = open database; IO_WriteOnly = saveas database) + **/ + void setMode(int openMode); + /** Return URL of database + * @return - pseudo-URL of database selected by user + **/ + const KURL selectedURL(); + +public slots: + void slotDriverSelected(TQListBoxItem *driver); + void slotHelp(); + void slotGenerateSQL(); +private: + void setError(); + int m_mode; + MyMoneyDbDrivers m_map; + kMandatoryFieldGroup* m_requiredFields; +}; + +#endif diff --git a/kmymoney2/dialogs/tdeselectdatabasedlgdecl.ui b/kmymoney2/dialogs/tdeselectdatabasedlgdecl.ui new file mode 100644 index 0000000..5e756a7 --- /dev/null +++ b/kmymoney2/dialogs/tdeselectdatabasedlgdecl.ui @@ -0,0 +1,250 @@ + +TDESelectDatabaseDlgDecl + + + TDESelectDatabaseDlgDecl + + + + 0 + 0 + 449 + 640 + + + + KMyMoney - Select Database + + + + unnamed + + + + groupBox6 + + + CAUTION! + + + + unnamed + + + + kActiveLabel1 + + + + 10 + 1 + + + + NoFocus + + + <font color="#ff2727">This software is still in an experimental stage, and there are still some known response time problems. Please be patient; we are working on them. +As always, please make sure you have adequate backups of your data.</font> + + + + + + + groupBox1 + + + Database Type + + + + unnamed + + + + listDrivers + + + + + + + groupBox2 + + + Database Name + + + + unnamed + + + + textDbName + + + + + + + groupBox3 + + + Host Name + + + + unnamed + + + + textHostName + + + + + + + groupBox4 + + + User Name + + + + unnamed + + + + textUserName + + + + + + + groupBoxPassword + + + Password + + + + unnamed + + + + textPassword + + + Password + + + + + + + checkPreLoad + + + Preload &all data + + + + + layout3 + + + + unnamed + + + + buttonHelp + + + Help + + + + + spacer3 + + + Horizontal + + + Expanding + + + + 20 + 20 + + + + + + buttonSQL + + + &Generate SQL + + + + + spacer2 + + + Horizontal + + + Expanding + + + + 31 + 20 + + + + + + buttonOK + + + OK + + + true + + + + + buttonCancel + + + Ca&ncel + + + + + + + + + buttonOK + released() + TDESelectDatabaseDlgDecl + accept() + + + buttonCancel + released() + TDESelectDatabaseDlgDecl + reject() + + + + diff --git a/kmymoney2/dialogs/tdeselecttransactionsdlg.cpp b/kmymoney2/dialogs/tdeselecttransactionsdlg.cpp new file mode 100644 index 0000000..51968f1 --- /dev/null +++ b/kmymoney2/dialogs/tdeselecttransactionsdlg.cpp @@ -0,0 +1,178 @@ +/*************************************************************************** + kselecttransactionsdlg.cpp + ------------------- + begin : Wed May 16 2007 + copyright : (C) 2007 by Thomas Baumgart + email : ipwizard@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. * + * * + ***************************************************************************/ + +// ---------------------------------------------------------------------------- +// QT Includes + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include +#include +#include +#include +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include +#include +#include + +#include "kmergetransactionsdlg.h" + +TDESelectTransactionsDlg::TDESelectTransactionsDlg(const MyMoneyAccount& _account, TQWidget* parent, const char* name) : + TDESelectTransactionsDlgDecl(parent, name), + m_account(_account) +{ + // setup descriptive texts + setCaption(i18n("Select Transaction")); + m_description->setText(i18n("Select a transaction and press the OK button or use Cancel to select none.")); + + // clear current register contents + m_register->clear(); + + // no selection possible + m_register->setSelectionMode(TQTable::Single); + + // setup header font + TQFont font = KMyMoneyGlobalSettings::listHeaderFont(); + TQFontMetrics fm( font ); + int height = fm.lineSpacing()+6; + m_register->horizontalHeader()->setMinimumHeight(height); + m_register->horizontalHeader()->setMaximumHeight(height); + m_register->horizontalHeader()->setFont(font); + + // setup cell font + font = KMyMoneyGlobalSettings::listCellFont(); + m_register->setFont(font); + + // ... setup the register columns ... + m_register->setupRegister(m_account); + + // setup buttons + m_helpButton->setGuiItem(KStdGuiItem::help()); + buttonOk->setGuiItem(KStdGuiItem::ok()); + buttonCancel->setGuiItem(KStdGuiItem::cancel()); + + // default is to need at least one transaction selected + buttonOk->setDisabled(true); + + // catch some events from the register + m_register->installEventFilter(this); + + connect(m_register, TQT_SIGNAL(selectionChanged(const KMyMoneyRegister::SelectedTransactions&)), this, TQT_SLOT(slotEnableOk(const KMyMoneyRegister::SelectedTransactions&))); + connect(m_register, TQT_SIGNAL(editTransaction()), this, TQT_SLOT(accept())); + + connect(m_helpButton, TQT_SIGNAL(clicked()), this, TQT_SLOT(slotHelp())); +} + +void TDESelectTransactionsDlg::slotEnableOk(const KMyMoneyRegister::SelectedTransactions& list) +{ + buttonOk->setEnabled(list.count() != 0); +} + +void TDESelectTransactionsDlg::addTransaction(const MyMoneyTransaction& t) +{ + TQValueList::const_iterator it_s; + for(it_s = t.splits().begin(); it_s != t.splits().end(); ++it_s) { + if((*it_s).accountId() == m_account.id()) { + KMyMoneyRegister::Transaction* tr = KMyMoneyRegister::Register::transactionFactory(m_register, t, (*it_s), 0); + // force full detail display + tr->setNumRowsRegister(tr->numRowsRegister(true)); + break; + } + } +} + +int TDESelectTransactionsDlg::exec(void) +{ + m_register->updateRegister(true); + m_register->updateContents(); + + m_register->setFocus(); + + return TDESelectTransactionsDlgDecl::exec(); +} + +void TDESelectTransactionsDlg::slotHelp(void) +{ + // kapp->invokeHelp("details.ledgers.match"); +} + +void TDESelectTransactionsDlg::show(void) +{ + TDESelectTransactionsDlgDecl::show(); + m_register->resize(KMyMoneyRegister::DetailColumn); +} + +void TDESelectTransactionsDlg::resizeEvent(TQResizeEvent* ev) +{ + // don't forget the resizer + TDESelectTransactionsDlgDecl::resizeEvent(ev); + + // resize the register + m_register->resize(KMyMoneyRegister::DetailColumn); +} + +MyMoneyTransaction TDESelectTransactionsDlg::transaction(void) const +{ + MyMoneyTransaction t; + + TQValueList list; + list = m_register->selectedItems(); + if(list.count()) { + KMyMoneyRegister::Transaction* _t = dynamic_cast(list[0]); + if(_t) + t = _t->transaction(); + } + return t; +} + +bool TDESelectTransactionsDlg::eventFilter(TQObject* o, TQEvent* e) +{ + bool rc = false; + TQKeyEvent* k; + + if(TQT_BASE_OBJECT(o) == TQT_BASE_OBJECT(m_register)) { + switch(e->type()) { + case TQEvent::KeyPress: + k = dynamic_cast(e); + if((k->state() & TQt::KeyButtonMask) == 0) { + switch(k->key()) { + case TQt::Key_Return: + case TQt::Key_Enter: + if(buttonOk->isEnabled()) { + accept(); + rc = true; + } + // tricky fall through here + default: + break; + } + } + // tricky fall through here + default: + break; + } + } + return rc; +} + +#include "kselecttransactionsdlg.moc" +// vim:cin:si:ai:et:ts=2:sw=2: diff --git a/kmymoney2/dialogs/tdeselecttransactionsdlg.h b/kmymoney2/dialogs/tdeselecttransactionsdlg.h new file mode 100644 index 0000000..4eeaea2 --- /dev/null +++ b/kmymoney2/dialogs/tdeselecttransactionsdlg.h @@ -0,0 +1,74 @@ +/*************************************************************************** + kselecttransactionsdlg.h + ------------------- + begin : Wed May 16 2007 + copyright : (C) 2007 by Thomas Baumgart + email : ipwizard@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 KSELECTTRANSACTIONSDLG_H +#define KSELECTTRANSACTIONSDLG_H + +// ---------------------------------------------------------------------------- +// QT Includes + +class TQResizeEvent; + +// ---------------------------------------------------------------------------- +// KDE Includes + +#include + +// ---------------------------------------------------------------------------- +// Project Includes + +#include +#include + +#include "../dialogs/kselecttransactionsdlgdecl.h" + +class TDESelectTransactionsDlg: public TDESelectTransactionsDlgDecl +{ + Q_OBJECT + +public: + TDESelectTransactionsDlg(const MyMoneyAccount& account, TQWidget* parent = 0, const char* name = 0); + + /** + * Adds the transaction @a t to the dialog + */ + void addTransaction(const MyMoneyTransaction& t); + int exec(void); + void show(void); + + MyMoneyTransaction transaction(void) const; + + bool eventFilter(TQObject* o, TQEvent* e); + +public slots: + virtual void slotHelp(); + +protected slots: + void slotEnableOk(const KMyMoneyRegister::SelectedTransactions& list); + +protected: + void resizeEvent(TQResizeEvent* ev); + +private: + /** + * The account in which the transactions are displayed + */ + MyMoneyAccount m_account; +}; + +#endif // KMERGETRANSACTIONSDLG_H +// vim:cin:si:ai:et:ts=2:sw=2: diff --git a/kmymoney2/dialogs/tdeselecttransactionsdlgdecl.ui b/kmymoney2/dialogs/tdeselecttransactionsdlgdecl.ui new file mode 100644 index 0000000..24bc6f0 --- /dev/null +++ b/kmymoney2/dialogs/tdeselecttransactionsdlgdecl.ui @@ -0,0 +1,174 @@ + +TDESelectTransactionsDlgDecl + + + TDESelectTransactionsDlgDecl + + + + 0 + 0 + 794 + 456 + + + + xxx + + + true + + + + unnamed + + + + m_description + + + NoFocus + + + xxx + + + + + + Security + + + + + Details + + + + + C + + + + + Payment + + + + + Deposit + + + + + Quantity + + + + + Price + + + + + Value + + + + + Balance + + + + m_register + + + + 7 + 7 + 0 + 3 + + + + 0 + + + 12 + + + + + layout2 + + + + unnamed + + + + m_helpButton + + + Help + + + + + Horizontal Spacing2 + + + Horizontal + + + Expanding + + + + 430 + 20 + + + + + + buttonOk + + + OK + + + true + + + true + + + + + buttonCancel + + + Cancel + + + + + + + + + buttonOk + clicked() + TDESelectTransactionsDlgDecl + accept() + + + buttonCancel + clicked() + TDESelectTransactionsDlgDecl + reject() + + + + diff --git a/kmymoney2/widgets/klistviewsearchline.cpp b/kmymoney2/widgets/klistviewsearchline.cpp deleted file mode 100644 index 0af29d7..0000000 --- a/kmymoney2/widgets/klistviewsearchline.cpp +++ /dev/null @@ -1,507 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (c) 2003 Scott Wheeler - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#include "klistviewsearchline.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#define KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID 2004 - -class TDEListViewSearchLine::TDEListViewSearchLinePrivate -{ -public: - TDEListViewSearchLinePrivate() : - listView(0), - caseSensitive(false), - activeSearch(false), - keepParentsVisible(true), - queuedSearches(0) {} - - TDEListView *listView; - bool caseSensitive; - bool activeSearch; - bool keepParentsVisible; - TQString search; - int queuedSearches; - TQValueList searchColumns; -}; - -//////////////////////////////////////////////////////////////////////////////// -// public methods -//////////////////////////////////////////////////////////////////////////////// - -TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, TDEListView *listView, const char *name) : - KLineEdit(parent, name) -{ - d = new TDEListViewSearchLinePrivate; - - d->listView = listView; - - connect(this, TQT_SIGNAL(textChanged(const TQString &)), - this, TQT_SLOT(queueSearch(const TQString &))); - - if(listView) { - connect(listView, TQT_SIGNAL(destroyed()), - this, TQT_SLOT(listViewDeleted())); - -#if KDE_IS_VERSION(3,3,0) - connect(listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), - this, TQT_SLOT(itemAdded(TQListViewItem *))); -#endif - } - else - setEnabled(false); -} - -TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, const char *name) : - KLineEdit(parent, name) -{ - d = new TDEListViewSearchLinePrivate; - - d->listView = 0; - - connect(this, TQT_SIGNAL(textChanged(const TQString &)), - this, TQT_SLOT(queueSearch(const TQString &))); - - setEnabled(false); -} - -TDEListViewSearchLine::~TDEListViewSearchLine() -{ - delete d; -} - -bool TDEListViewSearchLine::caseSensitive() const -{ - return d->caseSensitive; -} - -TQValueList TDEListViewSearchLine::searchColumns() const -{ - return d->searchColumns; -} - -bool TDEListViewSearchLine::keepParentsVisible() const -{ - return d->keepParentsVisible; -} - -TDEListView *TDEListViewSearchLine::listView() const -{ - return d->listView; -} - -//////////////////////////////////////////////////////////////////////////////// -// public slots -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::updateSearch(const TQString &s) -{ - if(!d->listView) - return; - - d->search = s.isNull() ? text() : s; - - // If there's a selected item that is visible, make sure that it's visible - // when the search changes too (assuming that it still matches). - - TQListViewItem *currentItem = 0; - - switch(d->listView->selectionMode()) - { - case TDEListView::NoSelection: - break; - case TDEListView::Single: - currentItem = d->listView->selectedItem(); - break; - default: - { - int flags = TQListViewItemIterator::Selected | TQListViewItemIterator::Visible; - for(TQListViewItemIterator it(d->listView, flags); - it.current() && !currentItem; - ++it) - { - if(d->listView->itemRect(it.current()).isValid()) - currentItem = it.current(); - } - } - } - - if(d->keepParentsVisible) - checkItemParentsVisible(d->listView->firstChild()); - else - checkItemParentsNotVisible(); - - if(currentItem) - d->listView->ensureItemVisible(currentItem); -} - -void TDEListViewSearchLine::setCaseSensitive(bool cs) -{ - d->caseSensitive = cs; -} - -void TDEListViewSearchLine::setKeepParentsVisible(bool v) -{ - d->keepParentsVisible = v; -} - -void TDEListViewSearchLine::setSearchColumns(const TQValueList &columns) -{ - d->searchColumns = columns; -} - -void TDEListViewSearchLine::setListView(TDEListView *lv) -{ - if(d->listView) { - disconnect(d->listView, TQT_SIGNAL(destroyed()), - this, TQT_SLOT(listViewDeleted())); - -#if KDE_IS_VERSION(3,3,0) - disconnect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), - this, TQT_SLOT(itemAdded(TQListViewItem *))); -#endif - } - - d->listView = lv; - - if(lv) { - connect(d->listView, TQT_SIGNAL(destroyed()), - this, TQT_SLOT(listViewDeleted())); - -#if KDE_IS_VERSION(3,3,0) - connect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), - this, TQT_SLOT(itemAdded(TQListViewItem *))); -#endif - } - - setEnabled(bool(lv)); -} - -//////////////////////////////////////////////////////////////////////////////// -// protected members -//////////////////////////////////////////////////////////////////////////////// - -bool TDEListViewSearchLine::itemMatches(const TQListViewItem *item, const TQString &s) const -{ - if(s.isEmpty()) - return true; - - // If the search column list is populated, search just the columns - // specifified. If it is empty default to searching all of the columns. - - if(!d->searchColumns.isEmpty()) { - TQValueList::ConstIterator it = d->searchColumns.begin(); - for(; it != d->searchColumns.end(); ++it) { - if(*it < item->listView()->columns() && - item->text(*it).find(s, 0, d->caseSensitive) >= 0) - return true; - } - } - else { - for(int i = 0; i < item->listView()->columns(); i++) { - if(item->listView()->columnWidth(i) > 0 && - item->text(i).find(s, 0, d->caseSensitive) >= 0) - { - return true; - } - } - } - - return false; -} - -TQPopupMenu *TDEListViewSearchLine::createPopupMenu() -{ - TQPopupMenu *popup = KLineEdit::createPopupMenu(); - - if (d->listView->columns()>1) { - TQPopupMenu *subMenu = new TQPopupMenu(popup); - connect(subMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(searchColumnsMenuActivated(int))); - - popup->insertSeparator(); - popup->insertItem(i18n("Search Columns"), subMenu); - - subMenu->insertItem(i18n("All Visible Columns"), KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID); - subMenu->insertSeparator(); - - bool allColumnsAreSearchColumns = true; - // TODO Make the entry order match the actual column order - TQHeader* const header = d->listView->header(); - int visibleColumns = 0; - for(int i = 0; i < d->listView->columns(); i++) { - if(d->listView->columnWidth(i)>0) { - TQString columnText = d->listView->columnText(i); - if(columnText.isEmpty()) { - int visiblePosition=1; - for(int j = 0; j < header->mapToIndex(i); j++) - if(d->listView->columnWidth(header->mapToSection(j))>0) - visiblePosition++; - columnText = i18n("Column number %1","Column No. %1").arg(visiblePosition); - } - subMenu->insertItem(columnText, visibleColumns); - if(d->searchColumns.isEmpty() || d->searchColumns.find(i) != d->searchColumns.end()) - subMenu->setItemChecked(visibleColumns, true); - else - allColumnsAreSearchColumns = false; - visibleColumns++; - } - } - subMenu->setItemChecked(KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID, allColumnsAreSearchColumns); - - // searchColumnsMenuActivated() relies on one possible "all" representation - if(allColumnsAreSearchColumns && !d->searchColumns.isEmpty()) - d->searchColumns.clear(); - } - - return popup; -} - -//////////////////////////////////////////////////////////////////////////////// -// protected slots -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::queueSearch(const TQString &search) -{ - d->queuedSearches++; - d->search = search; - TQTimer::singleShot(200, this, TQT_SLOT(activateSearch())); -} - -void TDEListViewSearchLine::activateSearch() -{ - --(d->queuedSearches); - - if(d->queuedSearches == 0) - updateSearch(d->search); -} - -//////////////////////////////////////////////////////////////////////////////// -// private slots -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::itemAdded(TQListViewItem *item) const -{ - item->setVisible(itemMatches(item, text())); -} - -void TDEListViewSearchLine::listViewDeleted() -{ - d->listView = 0; - setEnabled(false); -} - -void TDEListViewSearchLine::searchColumnsMenuActivated(int id) -{ - if(id == KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID) { - if(d->searchColumns.isEmpty()) - d->searchColumns.append(0); - else - d->searchColumns.clear(); - } - else { - if(d->searchColumns.find(id) != d->searchColumns.end()) - d->searchColumns.remove(id); - else { - if(d->searchColumns.isEmpty()) { - for(int i = 0; i < d->listView->columns(); i++) { - if(i != id) - d->searchColumns.append(i); - } - } - else - d->searchColumns.append(id); - } - } - updateSearch(); -} - -//////////////////////////////////////////////////////////////////////////////// -// private methods -//////////////////////////////////////////////////////////////////////////////// - -void TDEListViewSearchLine::checkItemParentsNotVisible() -{ - TQListViewItemIterator it(d->listView); - for(; it.current(); ++it) - { - TQListViewItem *item = it.current(); - if(itemMatches(item, d->search)) - item->setVisible(true); - else - item->setVisible(false); - } -} - -#include - -/** Check whether \p item, its siblings and their descendents should be shown. Show or hide the items as necessary. - * - * \p item The list view item to start showing / hiding items at. Typically, this is the first child of another item, or the - * the first child of the list view. - * \p highestHiddenParent The highest (closest to root) ancestor of \p item which is hidden. If 0, all parents of - * \p item must be visible. - * \return \c true if an item which should be visible is found, \c false if all items found should be hidden. If this function - * returns true and \p highestHiddenParent was not 0, highestHiddenParent will have been shown. - */ -bool TDEListViewSearchLine::checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent) -{ - bool visible = false; - TQListViewItem * first = item; - for(; item; item = item->nextSibling()) - { - //What we pass to our children as highestHiddenParent: - TQListViewItem * hhp = highestHiddenParent ? highestHiddenParent : item->isVisible() ? 0L : item; - bool childMatch = false; - if(item->firstChild() && checkItemParentsVisible(item->firstChild(), hhp)) - childMatch = true; - // Should this item be shown? It should if any children should be, or if it matches. - if(childMatch || itemMatches(item, d->search)) - { - visible = true; - if (highestHiddenParent) - { - highestHiddenParent->setVisible(true); - // Calling setVisible on our ancestor will unhide all its descendents. Hide the ones - // before us that should not be shown. - for(TQListViewItem *hide = first; hide != item; hide = hide->nextSibling()) - hide->setVisible(false); - highestHiddenParent = 0; - // If we matched, than none of our children matched, yet the setVisible() call on our - // ancestor unhid them, undo the damage: - if(!childMatch) - for(TQListViewItem *hide = item->firstChild(); hide; hide = hide->nextSibling()) - hide->setVisible(false); - } - else - item->setVisible(true); - } - else - item->setVisible(false); - } - return visible; -} - -//////////////////////////////////////////////////////////////////////////////// -// TDEListViewSearchLineWidget -//////////////////////////////////////////////////////////////////////////////// - -class TDEListViewSearchLineWidget::TDEListViewSearchLineWidgetPrivate -{ -public: - TDEListViewSearchLineWidgetPrivate() : listView(0), searchLine(0), clearButton(0) {} - TDEListView *listView; - TDEListViewSearchLine *searchLine; - TQToolButton *clearButton; -}; - -TDEListViewSearchLineWidget::TDEListViewSearchLineWidget(TDEListView *listView, - TQWidget *parent, - const char *name) : - TQHBox(parent, name) -{ - d = new TDEListViewSearchLineWidgetPrivate; - d->listView = listView; - - setSpacing(5); - - TQTimer::singleShot(0, this, TQT_SLOT(createWidgets())); -} - -TDEListViewSearchLineWidget::~TDEListViewSearchLineWidget() -{ - delete d; -} - -TDEListViewSearchLine *TDEListViewSearchLineWidget::createSearchLine(TDEListView *listView) -{ - if(!d->searchLine) - d->searchLine = new TDEListViewSearchLine(this, listView); - return d->searchLine; -} - -void TDEListViewSearchLineWidget::createWidgets() -{ - positionInToolBar(); - - if(!d->clearButton) { - d->clearButton = new TQToolButton(this); - TQIconSet icon = SmallIconSet(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"); - d->clearButton->setIconSet(icon); - } - - d->clearButton->show(); - - TQLabel *label = new TQLabel(i18n("S&earch:"), this, "kde toolbar widget"); - - d->searchLine = createSearchLine(d->listView); - d->searchLine->show(); - - label->setBuddy(d->searchLine); - label->show(); - - connect(d->clearButton, TQT_SIGNAL(clicked()), d->searchLine, TQT_SLOT(clear())); -} - -TDEListViewSearchLine *TDEListViewSearchLineWidget::searchLine() const -{ - return d->searchLine; -} - -void TDEListViewSearchLineWidget::positionInToolBar() -{ - TDEToolBar *toolBar = dynamic_cast(parent()); - - if(toolBar) { - - // Here we have The Big Ugly. Figure out how many widgets are in the - // and do a hack-ish iteration over them to find this widget so that we - // can insert the clear button before it. - - int widgetCount = toolBar->count(); - - for(int index = 0; index < widgetCount; index++) { - int id = toolBar->idAt(index); - if(toolBar->getWidget(id) == this) { - toolBar->setItemAutoSized(id); - if(!d->clearButton) { - TQString icon = TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"; - d->clearButton = new TDEToolBarButton(icon, 2005, toolBar); - } - toolBar->insertWidget(2005, d->clearButton->width(), d->clearButton, index); - break; - } - } - } - - if(d->searchLine) - d->searchLine->show(); -} - -#include "klistviewsearchline.moc" diff --git a/kmymoney2/widgets/klistviewsearchline.h b/kmymoney2/widgets/klistviewsearchline.h deleted file mode 100644 index 2ffad3c..0000000 --- a/kmymoney2/widgets/klistviewsearchline.h +++ /dev/null @@ -1,260 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (c) 2003 Scott Wheeler - Adapted to be used with KMyMoney under KDE 3.2 .. 3.4 - - This library is free software; you can redistribute it and/or - modify it under the terms of the GNU Library General Public - License version 2 as published by the Free Software Foundation. - - This library 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 - Library General Public License for more details. - - You should have received a copy of the GNU Library General Public License - along with this library; see the file COPYING.LIB. If not, write to - the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, - Boston, MA 02110-1301, USA. -*/ - -#ifndef KLISTVIEWSEARCHLINE_H -#define KLISTVIEWSEARCHLINE_H - -#include -#include -#include - -class TDEListView; -class TQListViewItem; -class TQToolButton; - -/** - * This class makes it easy to add a search line for filtering the items in a - * listview based on a simple text search. - * - * No changes to the application other than instantiating this class with an - * appropriate TDEListView should be needed. - * - * @since 3.3 - */ - -class KMYMONEY_EXPORT TDEListViewSearchLine : public KLineEdit -{ - Q_OBJECT - - -public: - - /** - * Constructs a TDEListViewSearchLine with \a listView being the TDEListView to - * be filtered. - * - * If \a listView is null then the widget will be disabled until a listview - * is set with setListView(). - */ - TDEListViewSearchLine(TQWidget *parent = 0, TDEListView *listView = 0, const char *name = 0); - - /** - * Constructs a TDEListViewSearchLine without any TDEListView to filter. The - * TDEListView object has to be set later with setListView(). - */ - TDEListViewSearchLine(TQWidget *parent, const char *name); - - /** - * Destroys the TDEListViewSearchLine. - */ - virtual ~TDEListViewSearchLine(); - - /** - * Returns true if the search is case sensitive. This defaults to false. - * - * @see setCaseSensitive() - */ - bool caseSensitive() const; - - /** - * Returns the current list of columns that will be searched. If the - * returned list is empty all visible columns will be searched. - * - * @see setSearchColumns - */ - TQValueList searchColumns() const; - - /** - * If this is true (the default) then the parents of matched items will also - * be shown. - * - * @see setKeepParentsVisible() - */ - bool keepParentsVisible() const; - - /** - * Returns the listview that is currently filtered by the search. - * - * @see setListView() - */ - TDEListView *listView() const; - -public slots: - /** - * Updates search to only make visible the items that match \a s. If - * \a s is null then the line edit's text will be used. - */ - virtual void updateSearch(const TQString &s = TQString()); - - /** - * Make the search case sensitive or case insensitive. - * - * @see caseSenstive() - */ - void setCaseSensitive(bool cs); - - /** - * When a search is active on a list that's organized into a tree view if - * a parent or ancesestor of an item is does not match the search then it - * will be hidden and as such so too will any children that match. - * - * If this is set to true (the default) then the parents of matching items - * will be shown. - * - * @see keepParentsVisible - */ - void setKeepParentsVisible(bool v); - - /** - * Sets the list of columns to be searched. The default is to search all, - * visible columns which can be restored by passing \a columns as an empty - * list. - * - * @see searchColumns - */ - void setSearchColumns(const TQValueList &columns); - - /** - * Sets the TDEListView that is filtered by this search line. If \a lv is null - * then the widget will be disabled. - * - * @see listView() - */ - void setListView(TDEListView *lv); - -protected: - - /** - * Returns true if \a item matches the search \a s. This will be evaluated - * based on the value of caseSensitive(). This can be overridden in - * subclasses to implement more complicated matching schemes. - */ - virtual bool itemMatches(const TQListViewItem *item, const TQString &s) const; - - /** - * Re-implemented for internal reasons. API not affected. - * - * See TQLineEdit::mousePressEvent(). - */ - virtual TQPopupMenu *createPopupMenu(); - -protected slots: - /** - * When keys are pressed a new search string is created and a timer is - * activated. The most recent search is activated when this timer runs out - * if another key has not yet been pressed. - * - * This method makes @param search the most recent search and starts the - * timer. - * - * Together with activateSearch() this makes it such that searches are not - * started until there is a short break in the users typing. - * - * @see activateSearch() - */ - void queueSearch(const TQString &search); - - /** - * When the timer started with queueSearch() expires this slot is called. - * If there has been another timer started then this slot does nothing. - * However if there are no other pending searches this starts the list view - * search. - * - * @see queueSearch() - */ - void activateSearch(); - -private: - - /** - * This is used in case parent items of matching items shouldn't be - * visible. It hides all items that don't match the search string. - */ - void checkItemParentsNotVisible(); - - /** - * This is used in case parent items of matching items should be visible. - * It makes a recursive call to all children. It returns true if at least - * one item in the subtree with the given root item is visible. - */ - bool checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent = 0); - -private slots: - void itemAdded(TQListViewItem *item) const; - void listViewDeleted(); - void searchColumnsMenuActivated(int); - -private: - class TDEListViewSearchLinePrivate; - TDEListViewSearchLinePrivate *d; -}; - -/** - * Creates a widget featuring a TDEListViewSearchLine, a label with the text - * "Search" and a button to clear the search. - * - * @since 3.4 - */ -class KMYMONEY_EXPORT TDEListViewSearchLineWidget : public TQHBox -{ - Q_OBJECT - - -public: - /** - * Creates a TDEListViewSearchLineWidget for \a listView with \a parent as the - * parent with and \a name. - */ - TDEListViewSearchLineWidget(TDEListView *listView = 0, TQWidget *parent = 0, - const char *name = 0); - - /** - * Destroys the TDEListViewSearchLineWidget - */ - ~TDEListViewSearchLineWidget(); - - /** - * Creates the search line. This can be useful to reimplement in cases where - * a TDEListViewSearchLine subclass is used. - */ - virtual TDEListViewSearchLine *createSearchLine(TDEListView *listView); - - /** - * Returns a pointer to the search line. - */ - TDEListViewSearchLine *searchLine() const; - -protected slots: - /** - * Creates the widgets inside of the widget. This is called from the - * constructor via a single shot timer so that it it guaranteed to run - * after construction is complete. This makes it suitable for overriding in - * subclasses. - */ - virtual void createWidgets(); - -private slots: - void positionInToolBar(); - -private: - class TDEListViewSearchLineWidgetPrivate; - TDEListViewSearchLineWidgetPrivate *d; -}; - -#endif diff --git a/kmymoney2/widgets/kmymoneychecklistitem.cpp b/kmymoney2/widgets/kmymoneychecklistitem.cpp deleted file mode 100644 index b292567..0000000 --- a/kmymoney2/widgets/kmymoneychecklistitem.cpp +++ /dev/null @@ -1,151 +0,0 @@ -/*************************************************************************** - kmymoneychecklistitem - ------------------- - begin : Wed Jun 28 2006 - copyright : (C) 2006 by Thomas Baumgart - email : Thomas Baumgart - ***************************************************************************/ - -/*************************************************************************** - * * - * 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. * - * * - ***************************************************************************/ - -// ---------------------------------------------------------------------------- -// QT Includes - -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes - -// ---------------------------------------------------------------------------- -// Project Includes - -#include "kmymoneychecklistitem.h" -#include "kmymoneylistviewitem.h" -#include "../kmymoneyglobalsettings.h" - -KMyMoneyCheckListItem::KMyMoneyCheckListItem(TQListView* parent, const TQString& txt, const TQString& key, const TQString& id, Type type) : - TQCheckListItem(parent, txt, type), - m_key(key), - m_id(id), - m_isOdd(0), - m_isKnown(0) -{ - setOn(true); - if(key.isEmpty()) - m_key = txt; -} - -KMyMoneyCheckListItem::KMyMoneyCheckListItem(TQListViewItem* parent, const TQString& txt, const TQString& key, const TQString& id, Type type) : - TQCheckListItem(parent, txt, type), - m_key(key), - m_id(id), - m_isOdd(0), - m_isKnown(0) -{ - setOn(true); - if(key.isEmpty()) - m_key = txt; -} - -KMyMoneyCheckListItem::KMyMoneyCheckListItem(TQListView* parent, TQListViewItem* after, const TQString& txt, const TQString& key, const TQString& id, Type type) : - TQCheckListItem(parent, after, txt, type), - m_key(key), - m_id(id), - m_isOdd(0), - m_isKnown(0) -{ - setOn(true); - if(key.isEmpty()) - m_key = txt; -} - -KMyMoneyCheckListItem::~KMyMoneyCheckListItem() -{ -} - -TQString KMyMoneyCheckListItem::key(int column, bool ascending) const -{ - Q_UNUSED(ascending); - - if(column == 0) - return m_key[0] + text(0); - return m_key.mid(1); -} - -void KMyMoneyCheckListItem::stateChange(bool state) -{ - emit stateChanged(state); -} - -void KMyMoneyCheckListItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment) -{ - TQColorGroup _cg = cg; - _cg.setColor(TQColorGroup::Base, backgroundColor()); - - // write the groups in bold - TQFont f = p->font(); - f.setBold(!isSelectable()); - p->setFont(f); - - TQCheckListItem::paintCell(p, _cg, column, width, alignment); -} - -const TQColor KMyMoneyCheckListItem::backgroundColor() -{ - return isAlternate() ? KMyMoneyGlobalSettings::listBGColor() : KMyMoneyGlobalSettings::listColor(); -} - -bool KMyMoneyCheckListItem::isAlternate(void) -{ -// logic taken from TDEListViewItem::isAlternate() - KMyMoneyCheckListItem* ciAbove; - KMyMoneyListViewItem* liAbove; - ciAbove = dynamic_cast (itemAbove()); - liAbove = dynamic_cast (itemAbove()); - - m_isKnown = ciAbove ? ciAbove->m_isKnown : (liAbove ? liAbove->m_isKnown : true); - if(m_isKnown) { - m_isOdd = ciAbove ? !ciAbove->m_isOdd : (liAbove ? !liAbove->m_isOdd : false); - } else { - KMyMoneyCheckListItem* clItem; - KMyMoneyListViewItem* liItem; - bool previous = true; - if(TQListViewItem::parent()) { - clItem = dynamic_cast(TQListViewItem::parent()); - liItem = dynamic_cast(TQListViewItem::parent()); - if(clItem) - previous = clItem->m_isOdd; - else - previous = liItem->m_isOdd; - clItem = dynamic_cast(TQListViewItem::parent()->firstChild()); - liItem = dynamic_cast(TQListViewItem::parent()->firstChild()); - } else { - clItem = dynamic_cast(listView()->firstChild()); - liItem = dynamic_cast(listView()->firstChild()); - } - while(clItem || liItem) { - if(clItem) { - clItem->m_isOdd = previous = !previous; - clItem->m_isKnown = true; - liItem = dynamic_cast(clItem->nextSibling()); - clItem = dynamic_cast(clItem->nextSibling()); - } else if(liItem) { - liItem->m_isOdd = previous = !previous; - liItem->m_isKnown = true; - clItem = dynamic_cast(liItem->nextSibling()); - liItem = dynamic_cast(liItem->nextSibling()); - } - } - } - return m_isOdd; -} - -#include "kmymoneychecklistitem.moc" diff --git a/kmymoney2/widgets/kmymoneychecklistitem.h b/kmymoney2/widgets/kmymoneychecklistitem.h deleted file mode 100644 index 1c5474d..0000000 --- a/kmymoney2/widgets/kmymoneychecklistitem.h +++ /dev/null @@ -1,94 +0,0 @@ -/*************************************************************************** - kmymoneychecklistitem - description - ------------------- - begin : Wed Jun 28 2006 - copyright : (C) 2006 by Thomas Baumgart - email : Thomas Baumgart - ***************************************************************************/ - -/*************************************************************************** - * * - * 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 KMYMONEYCHECKLISTITEM_H -#define KMYMONEYCHECKLISTITEM_H - -// ---------------------------------------------------------------------------- -// QT Includes - -#include -#include - -// ---------------------------------------------------------------------------- -// KDE Includes - -// ---------------------------------------------------------------------------- -// Project Includes - -class KMyMoneyListViewItem; - -/** - * This class implements a derived version of a TQCheckListItem that - * allows the storage of an engine object id with the object and emits - * a signal upon state change. - * - * @author Thomas Baumgart - */ -class KMyMoneyCheckListItem : public TQObject, public TQCheckListItem -{ - friend class KMyMoneyListViewItem; - - Q_OBJECT - -public: - KMyMoneyCheckListItem(TQListView *parent, const TQString& txt, const TQString& key, const TQString& id, Type type = TQCheckListItem::CheckBox); - KMyMoneyCheckListItem(TQListView *parent, TQListViewItem* after, const TQString& txt, const TQString& key, const TQString& id, Type type = TQCheckListItem::CheckBox); - KMyMoneyCheckListItem(TQListViewItem *parent, const TQString& txt, const TQString& key, const TQString& id, Type type = TQCheckListItem::CheckBox); - ~KMyMoneyCheckListItem(); - - const TQString& id(void) const { return m_id; }; - - /** - * use my own paint method - */ - void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment); - - /** - * use my own backgroundColor method - */ - const TQColor backgroundColor(); - - /** - * see TDEListViewItem::isAlternate() - */ - bool isAlternate(void); - - /** - * This method returns a const reference to the key passed to the constructor. The column - * defines what is returned: For @a column equals 0, the first character passed as @a key to - * the constructor concatenated with the value returned by text(0) is returned. For @a column - * equals to 1, the @a key as passed to the constructor except the first character is returned. - */ - TQString key(int column, bool ascending) const; - -signals: - void stateChanged(bool); - -protected: - virtual void stateChange(bool); - -private: - TQString m_key; - TQString m_id; - // copied from TDEListViewItem() - unsigned int m_isOdd : 1; - unsigned int m_isKnown : 1; - unsigned int m_unused : 30; -}; - -#endif diff --git a/kmymoney2/widgets/kmymoneychectdelistitem.cpp b/kmymoney2/widgets/kmymoneychectdelistitem.cpp new file mode 100644 index 0000000..b292567 --- /dev/null +++ b/kmymoney2/widgets/kmymoneychectdelistitem.cpp @@ -0,0 +1,151 @@ +/*************************************************************************** + kmymoneychecklistitem + ------------------- + begin : Wed Jun 28 2006 + copyright : (C) 2006 by Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * 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. * + * * + ***************************************************************************/ + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +#include "kmymoneychecklistitem.h" +#include "kmymoneylistviewitem.h" +#include "../kmymoneyglobalsettings.h" + +KMyMoneyCheckListItem::KMyMoneyCheckListItem(TQListView* parent, const TQString& txt, const TQString& key, const TQString& id, Type type) : + TQCheckListItem(parent, txt, type), + m_key(key), + m_id(id), + m_isOdd(0), + m_isKnown(0) +{ + setOn(true); + if(key.isEmpty()) + m_key = txt; +} + +KMyMoneyCheckListItem::KMyMoneyCheckListItem(TQListViewItem* parent, const TQString& txt, const TQString& key, const TQString& id, Type type) : + TQCheckListItem(parent, txt, type), + m_key(key), + m_id(id), + m_isOdd(0), + m_isKnown(0) +{ + setOn(true); + if(key.isEmpty()) + m_key = txt; +} + +KMyMoneyCheckListItem::KMyMoneyCheckListItem(TQListView* parent, TQListViewItem* after, const TQString& txt, const TQString& key, const TQString& id, Type type) : + TQCheckListItem(parent, after, txt, type), + m_key(key), + m_id(id), + m_isOdd(0), + m_isKnown(0) +{ + setOn(true); + if(key.isEmpty()) + m_key = txt; +} + +KMyMoneyCheckListItem::~KMyMoneyCheckListItem() +{ +} + +TQString KMyMoneyCheckListItem::key(int column, bool ascending) const +{ + Q_UNUSED(ascending); + + if(column == 0) + return m_key[0] + text(0); + return m_key.mid(1); +} + +void KMyMoneyCheckListItem::stateChange(bool state) +{ + emit stateChanged(state); +} + +void KMyMoneyCheckListItem::paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment) +{ + TQColorGroup _cg = cg; + _cg.setColor(TQColorGroup::Base, backgroundColor()); + + // write the groups in bold + TQFont f = p->font(); + f.setBold(!isSelectable()); + p->setFont(f); + + TQCheckListItem::paintCell(p, _cg, column, width, alignment); +} + +const TQColor KMyMoneyCheckListItem::backgroundColor() +{ + return isAlternate() ? KMyMoneyGlobalSettings::listBGColor() : KMyMoneyGlobalSettings::listColor(); +} + +bool KMyMoneyCheckListItem::isAlternate(void) +{ +// logic taken from TDEListViewItem::isAlternate() + KMyMoneyCheckListItem* ciAbove; + KMyMoneyListViewItem* liAbove; + ciAbove = dynamic_cast (itemAbove()); + liAbove = dynamic_cast (itemAbove()); + + m_isKnown = ciAbove ? ciAbove->m_isKnown : (liAbove ? liAbove->m_isKnown : true); + if(m_isKnown) { + m_isOdd = ciAbove ? !ciAbove->m_isOdd : (liAbove ? !liAbove->m_isOdd : false); + } else { + KMyMoneyCheckListItem* clItem; + KMyMoneyListViewItem* liItem; + bool previous = true; + if(TQListViewItem::parent()) { + clItem = dynamic_cast(TQListViewItem::parent()); + liItem = dynamic_cast(TQListViewItem::parent()); + if(clItem) + previous = clItem->m_isOdd; + else + previous = liItem->m_isOdd; + clItem = dynamic_cast(TQListViewItem::parent()->firstChild()); + liItem = dynamic_cast(TQListViewItem::parent()->firstChild()); + } else { + clItem = dynamic_cast(listView()->firstChild()); + liItem = dynamic_cast(listView()->firstChild()); + } + while(clItem || liItem) { + if(clItem) { + clItem->m_isOdd = previous = !previous; + clItem->m_isKnown = true; + liItem = dynamic_cast(clItem->nextSibling()); + clItem = dynamic_cast(clItem->nextSibling()); + } else if(liItem) { + liItem->m_isOdd = previous = !previous; + liItem->m_isKnown = true; + clItem = dynamic_cast(liItem->nextSibling()); + liItem = dynamic_cast(liItem->nextSibling()); + } + } + } + return m_isOdd; +} + +#include "kmymoneychecklistitem.moc" diff --git a/kmymoney2/widgets/kmymoneychectdelistitem.h b/kmymoney2/widgets/kmymoneychectdelistitem.h new file mode 100644 index 0000000..1c5474d --- /dev/null +++ b/kmymoney2/widgets/kmymoneychectdelistitem.h @@ -0,0 +1,94 @@ +/*************************************************************************** + kmymoneychecklistitem - description + ------------------- + begin : Wed Jun 28 2006 + copyright : (C) 2006 by Thomas Baumgart + email : Thomas Baumgart + ***************************************************************************/ + +/*************************************************************************** + * * + * 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 KMYMONEYCHECKLISTITEM_H +#define KMYMONEYCHECKLISTITEM_H + +// ---------------------------------------------------------------------------- +// QT Includes + +#include +#include + +// ---------------------------------------------------------------------------- +// KDE Includes + +// ---------------------------------------------------------------------------- +// Project Includes + +class KMyMoneyListViewItem; + +/** + * This class implements a derived version of a TQCheckListItem that + * allows the storage of an engine object id with the object and emits + * a signal upon state change. + * + * @author Thomas Baumgart + */ +class KMyMoneyCheckListItem : public TQObject, public TQCheckListItem +{ + friend class KMyMoneyListViewItem; + + Q_OBJECT + +public: + KMyMoneyCheckListItem(TQListView *parent, const TQString& txt, const TQString& key, const TQString& id, Type type = TQCheckListItem::CheckBox); + KMyMoneyCheckListItem(TQListView *parent, TQListViewItem* after, const TQString& txt, const TQString& key, const TQString& id, Type type = TQCheckListItem::CheckBox); + KMyMoneyCheckListItem(TQListViewItem *parent, const TQString& txt, const TQString& key, const TQString& id, Type type = TQCheckListItem::CheckBox); + ~KMyMoneyCheckListItem(); + + const TQString& id(void) const { return m_id; }; + + /** + * use my own paint method + */ + void paintCell(TQPainter *p, const TQColorGroup &cg, int column, int width, int alignment); + + /** + * use my own backgroundColor method + */ + const TQColor backgroundColor(); + + /** + * see TDEListViewItem::isAlternate() + */ + bool isAlternate(void); + + /** + * This method returns a const reference to the key passed to the constructor. The column + * defines what is returned: For @a column equals 0, the first character passed as @a key to + * the constructor concatenated with the value returned by text(0) is returned. For @a column + * equals to 1, the @a key as passed to the constructor except the first character is returned. + */ + TQString key(int column, bool ascending) const; + +signals: + void stateChanged(bool); + +protected: + virtual void stateChange(bool); + +private: + TQString m_key; + TQString m_id; + // copied from TDEListViewItem() + unsigned int m_isOdd : 1; + unsigned int m_isKnown : 1; + unsigned int m_unused : 30; +}; + +#endif diff --git a/kmymoney2/widgets/tdelistviewsearchline.cpp b/kmymoney2/widgets/tdelistviewsearchline.cpp new file mode 100644 index 0000000..0af29d7 --- /dev/null +++ b/kmymoney2/widgets/tdelistviewsearchline.cpp @@ -0,0 +1,507 @@ +/* This file is part of the KDE libraries + Copyright (c) 2003 Scott Wheeler + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "klistviewsearchline.h" + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#define KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID 2004 + +class TDEListViewSearchLine::TDEListViewSearchLinePrivate +{ +public: + TDEListViewSearchLinePrivate() : + listView(0), + caseSensitive(false), + activeSearch(false), + keepParentsVisible(true), + queuedSearches(0) {} + + TDEListView *listView; + bool caseSensitive; + bool activeSearch; + bool keepParentsVisible; + TQString search; + int queuedSearches; + TQValueList searchColumns; +}; + +//////////////////////////////////////////////////////////////////////////////// +// public methods +//////////////////////////////////////////////////////////////////////////////// + +TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, TDEListView *listView, const char *name) : + KLineEdit(parent, name) +{ + d = new TDEListViewSearchLinePrivate; + + d->listView = listView; + + connect(this, TQT_SIGNAL(textChanged(const TQString &)), + this, TQT_SLOT(queueSearch(const TQString &))); + + if(listView) { + connect(listView, TQT_SIGNAL(destroyed()), + this, TQT_SLOT(listViewDeleted())); + +#if KDE_IS_VERSION(3,3,0) + connect(listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), + this, TQT_SLOT(itemAdded(TQListViewItem *))); +#endif + } + else + setEnabled(false); +} + +TDEListViewSearchLine::TDEListViewSearchLine(TQWidget *parent, const char *name) : + KLineEdit(parent, name) +{ + d = new TDEListViewSearchLinePrivate; + + d->listView = 0; + + connect(this, TQT_SIGNAL(textChanged(const TQString &)), + this, TQT_SLOT(queueSearch(const TQString &))); + + setEnabled(false); +} + +TDEListViewSearchLine::~TDEListViewSearchLine() +{ + delete d; +} + +bool TDEListViewSearchLine::caseSensitive() const +{ + return d->caseSensitive; +} + +TQValueList TDEListViewSearchLine::searchColumns() const +{ + return d->searchColumns; +} + +bool TDEListViewSearchLine::keepParentsVisible() const +{ + return d->keepParentsVisible; +} + +TDEListView *TDEListViewSearchLine::listView() const +{ + return d->listView; +} + +//////////////////////////////////////////////////////////////////////////////// +// public slots +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::updateSearch(const TQString &s) +{ + if(!d->listView) + return; + + d->search = s.isNull() ? text() : s; + + // If there's a selected item that is visible, make sure that it's visible + // when the search changes too (assuming that it still matches). + + TQListViewItem *currentItem = 0; + + switch(d->listView->selectionMode()) + { + case TDEListView::NoSelection: + break; + case TDEListView::Single: + currentItem = d->listView->selectedItem(); + break; + default: + { + int flags = TQListViewItemIterator::Selected | TQListViewItemIterator::Visible; + for(TQListViewItemIterator it(d->listView, flags); + it.current() && !currentItem; + ++it) + { + if(d->listView->itemRect(it.current()).isValid()) + currentItem = it.current(); + } + } + } + + if(d->keepParentsVisible) + checkItemParentsVisible(d->listView->firstChild()); + else + checkItemParentsNotVisible(); + + if(currentItem) + d->listView->ensureItemVisible(currentItem); +} + +void TDEListViewSearchLine::setCaseSensitive(bool cs) +{ + d->caseSensitive = cs; +} + +void TDEListViewSearchLine::setKeepParentsVisible(bool v) +{ + d->keepParentsVisible = v; +} + +void TDEListViewSearchLine::setSearchColumns(const TQValueList &columns) +{ + d->searchColumns = columns; +} + +void TDEListViewSearchLine::setListView(TDEListView *lv) +{ + if(d->listView) { + disconnect(d->listView, TQT_SIGNAL(destroyed()), + this, TQT_SLOT(listViewDeleted())); + +#if KDE_IS_VERSION(3,3,0) + disconnect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), + this, TQT_SLOT(itemAdded(TQListViewItem *))); +#endif + } + + d->listView = lv; + + if(lv) { + connect(d->listView, TQT_SIGNAL(destroyed()), + this, TQT_SLOT(listViewDeleted())); + +#if KDE_IS_VERSION(3,3,0) + connect(d->listView, TQT_SIGNAL(itemAdded(TQListViewItem *)), + this, TQT_SLOT(itemAdded(TQListViewItem *))); +#endif + } + + setEnabled(bool(lv)); +} + +//////////////////////////////////////////////////////////////////////////////// +// protected members +//////////////////////////////////////////////////////////////////////////////// + +bool TDEListViewSearchLine::itemMatches(const TQListViewItem *item, const TQString &s) const +{ + if(s.isEmpty()) + return true; + + // If the search column list is populated, search just the columns + // specifified. If it is empty default to searching all of the columns. + + if(!d->searchColumns.isEmpty()) { + TQValueList::ConstIterator it = d->searchColumns.begin(); + for(; it != d->searchColumns.end(); ++it) { + if(*it < item->listView()->columns() && + item->text(*it).find(s, 0, d->caseSensitive) >= 0) + return true; + } + } + else { + for(int i = 0; i < item->listView()->columns(); i++) { + if(item->listView()->columnWidth(i) > 0 && + item->text(i).find(s, 0, d->caseSensitive) >= 0) + { + return true; + } + } + } + + return false; +} + +TQPopupMenu *TDEListViewSearchLine::createPopupMenu() +{ + TQPopupMenu *popup = KLineEdit::createPopupMenu(); + + if (d->listView->columns()>1) { + TQPopupMenu *subMenu = new TQPopupMenu(popup); + connect(subMenu, TQT_SIGNAL(activated(int)), this, TQT_SLOT(searchColumnsMenuActivated(int))); + + popup->insertSeparator(); + popup->insertItem(i18n("Search Columns"), subMenu); + + subMenu->insertItem(i18n("All Visible Columns"), KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID); + subMenu->insertSeparator(); + + bool allColumnsAreSearchColumns = true; + // TODO Make the entry order match the actual column order + TQHeader* const header = d->listView->header(); + int visibleColumns = 0; + for(int i = 0; i < d->listView->columns(); i++) { + if(d->listView->columnWidth(i)>0) { + TQString columnText = d->listView->columnText(i); + if(columnText.isEmpty()) { + int visiblePosition=1; + for(int j = 0; j < header->mapToIndex(i); j++) + if(d->listView->columnWidth(header->mapToSection(j))>0) + visiblePosition++; + columnText = i18n("Column number %1","Column No. %1").arg(visiblePosition); + } + subMenu->insertItem(columnText, visibleColumns); + if(d->searchColumns.isEmpty() || d->searchColumns.find(i) != d->searchColumns.end()) + subMenu->setItemChecked(visibleColumns, true); + else + allColumnsAreSearchColumns = false; + visibleColumns++; + } + } + subMenu->setItemChecked(KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID, allColumnsAreSearchColumns); + + // searchColumnsMenuActivated() relies on one possible "all" representation + if(allColumnsAreSearchColumns && !d->searchColumns.isEmpty()) + d->searchColumns.clear(); + } + + return popup; +} + +//////////////////////////////////////////////////////////////////////////////// +// protected slots +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::queueSearch(const TQString &search) +{ + d->queuedSearches++; + d->search = search; + TQTimer::singleShot(200, this, TQT_SLOT(activateSearch())); +} + +void TDEListViewSearchLine::activateSearch() +{ + --(d->queuedSearches); + + if(d->queuedSearches == 0) + updateSearch(d->search); +} + +//////////////////////////////////////////////////////////////////////////////// +// private slots +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::itemAdded(TQListViewItem *item) const +{ + item->setVisible(itemMatches(item, text())); +} + +void TDEListViewSearchLine::listViewDeleted() +{ + d->listView = 0; + setEnabled(false); +} + +void TDEListViewSearchLine::searchColumnsMenuActivated(int id) +{ + if(id == KLISTVIEWSEARCHLINE_ALLVISIBLECOLUMNS_ID) { + if(d->searchColumns.isEmpty()) + d->searchColumns.append(0); + else + d->searchColumns.clear(); + } + else { + if(d->searchColumns.find(id) != d->searchColumns.end()) + d->searchColumns.remove(id); + else { + if(d->searchColumns.isEmpty()) { + for(int i = 0; i < d->listView->columns(); i++) { + if(i != id) + d->searchColumns.append(i); + } + } + else + d->searchColumns.append(id); + } + } + updateSearch(); +} + +//////////////////////////////////////////////////////////////////////////////// +// private methods +//////////////////////////////////////////////////////////////////////////////// + +void TDEListViewSearchLine::checkItemParentsNotVisible() +{ + TQListViewItemIterator it(d->listView); + for(; it.current(); ++it) + { + TQListViewItem *item = it.current(); + if(itemMatches(item, d->search)) + item->setVisible(true); + else + item->setVisible(false); + } +} + +#include + +/** Check whether \p item, its siblings and their descendents should be shown. Show or hide the items as necessary. + * + * \p item The list view item to start showing / hiding items at. Typically, this is the first child of another item, or the + * the first child of the list view. + * \p highestHiddenParent The highest (closest to root) ancestor of \p item which is hidden. If 0, all parents of + * \p item must be visible. + * \return \c true if an item which should be visible is found, \c false if all items found should be hidden. If this function + * returns true and \p highestHiddenParent was not 0, highestHiddenParent will have been shown. + */ +bool TDEListViewSearchLine::checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent) +{ + bool visible = false; + TQListViewItem * first = item; + for(; item; item = item->nextSibling()) + { + //What we pass to our children as highestHiddenParent: + TQListViewItem * hhp = highestHiddenParent ? highestHiddenParent : item->isVisible() ? 0L : item; + bool childMatch = false; + if(item->firstChild() && checkItemParentsVisible(item->firstChild(), hhp)) + childMatch = true; + // Should this item be shown? It should if any children should be, or if it matches. + if(childMatch || itemMatches(item, d->search)) + { + visible = true; + if (highestHiddenParent) + { + highestHiddenParent->setVisible(true); + // Calling setVisible on our ancestor will unhide all its descendents. Hide the ones + // before us that should not be shown. + for(TQListViewItem *hide = first; hide != item; hide = hide->nextSibling()) + hide->setVisible(false); + highestHiddenParent = 0; + // If we matched, than none of our children matched, yet the setVisible() call on our + // ancestor unhid them, undo the damage: + if(!childMatch) + for(TQListViewItem *hide = item->firstChild(); hide; hide = hide->nextSibling()) + hide->setVisible(false); + } + else + item->setVisible(true); + } + else + item->setVisible(false); + } + return visible; +} + +//////////////////////////////////////////////////////////////////////////////// +// TDEListViewSearchLineWidget +//////////////////////////////////////////////////////////////////////////////// + +class TDEListViewSearchLineWidget::TDEListViewSearchLineWidgetPrivate +{ +public: + TDEListViewSearchLineWidgetPrivate() : listView(0), searchLine(0), clearButton(0) {} + TDEListView *listView; + TDEListViewSearchLine *searchLine; + TQToolButton *clearButton; +}; + +TDEListViewSearchLineWidget::TDEListViewSearchLineWidget(TDEListView *listView, + TQWidget *parent, + const char *name) : + TQHBox(parent, name) +{ + d = new TDEListViewSearchLineWidgetPrivate; + d->listView = listView; + + setSpacing(5); + + TQTimer::singleShot(0, this, TQT_SLOT(createWidgets())); +} + +TDEListViewSearchLineWidget::~TDEListViewSearchLineWidget() +{ + delete d; +} + +TDEListViewSearchLine *TDEListViewSearchLineWidget::createSearchLine(TDEListView *listView) +{ + if(!d->searchLine) + d->searchLine = new TDEListViewSearchLine(this, listView); + return d->searchLine; +} + +void TDEListViewSearchLineWidget::createWidgets() +{ + positionInToolBar(); + + if(!d->clearButton) { + d->clearButton = new TQToolButton(this); + TQIconSet icon = SmallIconSet(TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"); + d->clearButton->setIconSet(icon); + } + + d->clearButton->show(); + + TQLabel *label = new TQLabel(i18n("S&earch:"), this, "kde toolbar widget"); + + d->searchLine = createSearchLine(d->listView); + d->searchLine->show(); + + label->setBuddy(d->searchLine); + label->show(); + + connect(d->clearButton, TQT_SIGNAL(clicked()), d->searchLine, TQT_SLOT(clear())); +} + +TDEListViewSearchLine *TDEListViewSearchLineWidget::searchLine() const +{ + return d->searchLine; +} + +void TDEListViewSearchLineWidget::positionInToolBar() +{ + TDEToolBar *toolBar = dynamic_cast(parent()); + + if(toolBar) { + + // Here we have The Big Ugly. Figure out how many widgets are in the + // and do a hack-ish iteration over them to find this widget so that we + // can insert the clear button before it. + + int widgetCount = toolBar->count(); + + for(int index = 0; index < widgetCount; index++) { + int id = toolBar->idAt(index); + if(toolBar->getWidget(id) == this) { + toolBar->setItemAutoSized(id); + if(!d->clearButton) { + TQString icon = TQApplication::reverseLayout() ? "clear_left" : "locationbar_erase"; + d->clearButton = new TDEToolBarButton(icon, 2005, toolBar); + } + toolBar->insertWidget(2005, d->clearButton->width(), d->clearButton, index); + break; + } + } + } + + if(d->searchLine) + d->searchLine->show(); +} + +#include "klistviewsearchline.moc" diff --git a/kmymoney2/widgets/tdelistviewsearchline.h b/kmymoney2/widgets/tdelistviewsearchline.h new file mode 100644 index 0000000..2ffad3c --- /dev/null +++ b/kmymoney2/widgets/tdelistviewsearchline.h @@ -0,0 +1,260 @@ +/* This file is part of the KDE libraries + Copyright (c) 2003 Scott Wheeler + Adapted to be used with KMyMoney under KDE 3.2 .. 3.4 + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License version 2 as published by the Free Software Foundation. + + This library 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KLISTVIEWSEARCHLINE_H +#define KLISTVIEWSEARCHLINE_H + +#include +#include +#include + +class TDEListView; +class TQListViewItem; +class TQToolButton; + +/** + * This class makes it easy to add a search line for filtering the items in a + * listview based on a simple text search. + * + * No changes to the application other than instantiating this class with an + * appropriate TDEListView should be needed. + * + * @since 3.3 + */ + +class KMYMONEY_EXPORT TDEListViewSearchLine : public KLineEdit +{ + Q_OBJECT + + +public: + + /** + * Constructs a TDEListViewSearchLine with \a listView being the TDEListView to + * be filtered. + * + * If \a listView is null then the widget will be disabled until a listview + * is set with setListView(). + */ + TDEListViewSearchLine(TQWidget *parent = 0, TDEListView *listView = 0, const char *name = 0); + + /** + * Constructs a TDEListViewSearchLine without any TDEListView to filter. The + * TDEListView object has to be set later with setListView(). + */ + TDEListViewSearchLine(TQWidget *parent, const char *name); + + /** + * Destroys the TDEListViewSearchLine. + */ + virtual ~TDEListViewSearchLine(); + + /** + * Returns true if the search is case sensitive. This defaults to false. + * + * @see setCaseSensitive() + */ + bool caseSensitive() const; + + /** + * Returns the current list of columns that will be searched. If the + * returned list is empty all visible columns will be searched. + * + * @see setSearchColumns + */ + TQValueList searchColumns() const; + + /** + * If this is true (the default) then the parents of matched items will also + * be shown. + * + * @see setKeepParentsVisible() + */ + bool keepParentsVisible() const; + + /** + * Returns the listview that is currently filtered by the search. + * + * @see setListView() + */ + TDEListView *listView() const; + +public slots: + /** + * Updates search to only make visible the items that match \a s. If + * \a s is null then the line edit's text will be used. + */ + virtual void updateSearch(const TQString &s = TQString()); + + /** + * Make the search case sensitive or case insensitive. + * + * @see caseSenstive() + */ + void setCaseSensitive(bool cs); + + /** + * When a search is active on a list that's organized into a tree view if + * a parent or ancesestor of an item is does not match the search then it + * will be hidden and as such so too will any children that match. + * + * If this is set to true (the default) then the parents of matching items + * will be shown. + * + * @see keepParentsVisible + */ + void setKeepParentsVisible(bool v); + + /** + * Sets the list of columns to be searched. The default is to search all, + * visible columns which can be restored by passing \a columns as an empty + * list. + * + * @see searchColumns + */ + void setSearchColumns(const TQValueList &columns); + + /** + * Sets the TDEListView that is filtered by this search line. If \a lv is null + * then the widget will be disabled. + * + * @see listView() + */ + void setListView(TDEListView *lv); + +protected: + + /** + * Returns true if \a item matches the search \a s. This will be evaluated + * based on the value of caseSensitive(). This can be overridden in + * subclasses to implement more complicated matching schemes. + */ + virtual bool itemMatches(const TQListViewItem *item, const TQString &s) const; + + /** + * Re-implemented for internal reasons. API not affected. + * + * See TQLineEdit::mousePressEvent(). + */ + virtual TQPopupMenu *createPopupMenu(); + +protected slots: + /** + * When keys are pressed a new search string is created and a timer is + * activated. The most recent search is activated when this timer runs out + * if another key has not yet been pressed. + * + * This method makes @param search the most recent search and starts the + * timer. + * + * Together with activateSearch() this makes it such that searches are not + * started until there is a short break in the users typing. + * + * @see activateSearch() + */ + void queueSearch(const TQString &search); + + /** + * When the timer started with queueSearch() expires this slot is called. + * If there has been another timer started then this slot does nothing. + * However if there are no other pending searches this starts the list view + * search. + * + * @see queueSearch() + */ + void activateSearch(); + +private: + + /** + * This is used in case parent items of matching items shouldn't be + * visible. It hides all items that don't match the search string. + */ + void checkItemParentsNotVisible(); + + /** + * This is used in case parent items of matching items should be visible. + * It makes a recursive call to all children. It returns true if at least + * one item in the subtree with the given root item is visible. + */ + bool checkItemParentsVisible(TQListViewItem *item, TQListViewItem *highestHiddenParent = 0); + +private slots: + void itemAdded(TQListViewItem *item) const; + void listViewDeleted(); + void searchColumnsMenuActivated(int); + +private: + class TDEListViewSearchLinePrivate; + TDEListViewSearchLinePrivate *d; +}; + +/** + * Creates a widget featuring a TDEListViewSearchLine, a label with the text + * "Search" and a button to clear the search. + * + * @since 3.4 + */ +class KMYMONEY_EXPORT TDEListViewSearchLineWidget : public TQHBox +{ + Q_OBJECT + + +public: + /** + * Creates a TDEListViewSearchLineWidget for \a listView with \a parent as the + * parent with and \a name. + */ + TDEListViewSearchLineWidget(TDEListView *listView = 0, TQWidget *parent = 0, + const char *name = 0); + + /** + * Destroys the TDEListViewSearchLineWidget + */ + ~TDEListViewSearchLineWidget(); + + /** + * Creates the search line. This can be useful to reimplement in cases where + * a TDEListViewSearchLine subclass is used. + */ + virtual TDEListViewSearchLine *createSearchLine(TDEListView *listView); + + /** + * Returns a pointer to the search line. + */ + TDEListViewSearchLine *searchLine() const; + +protected slots: + /** + * Creates the widgets inside of the widget. This is called from the + * constructor via a single shot timer so that it it guaranteed to run + * after construction is complete. This makes it suitable for overriding in + * subclasses. + */ + virtual void createWidgets(); + +private slots: + void positionInToolBar(); + +private: + class TDEListViewSearchLineWidgetPrivate; + TDEListViewSearchLineWidgetPrivate *d; +}; + +#endif -- cgit v1.2.3