summaryrefslogtreecommitdiffabout
path: root/korganizer/kolistview.cpp
authorzautrix <zautrix>2005-06-07 20:23:54 (UTC)
committer zautrix <zautrix>2005-06-07 20:23:54 (UTC)
commit041729646fdaabd2ed69b4fc77c839efa81a7d2e (patch) (side-by-side diff)
tree82c78d5c25d18a79a8ae76aabf75ea40b91c26f2 /korganizer/kolistview.cpp
parentaa9a9368a7b38e34118b65a4e8efa7ea7ec0e8e4 (diff)
downloadkdepimpi-041729646fdaabd2ed69b4fc77c839efa81a7d2e.zip
kdepimpi-041729646fdaabd2ed69b4fc77c839efa81a7d2e.tar.gz
kdepimpi-041729646fdaabd2ed69b4fc77c839efa81a7d2e.tar.bz2
print list added to kopi
Diffstat (limited to 'korganizer/kolistview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--korganizer/kolistview.cpp82
1 files changed, 82 insertions, 0 deletions
diff --git a/korganizer/kolistview.cpp b/korganizer/kolistview.cpp
index bc52281..7022e02 100644
--- a/korganizer/kolistview.cpp
+++ b/korganizer/kolistview.cpp
@@ -1,113 +1,116 @@
/*
This file is part of KOrganizer.
Copyright (c) 1999 Preston Brown
Copyright (c) 2000,2001 Cornelius Schumacher <schumacher@kde.org>
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.
This program 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
As a special exception, permission is given to link this program
with any edition of Qt, and distribute the resulting executable,
without including the source code for Qt in the source distribution.
*/
#include <qlistview.h>
#include <qlayout.h>
#include <qlabel.h>
#include <qpopupmenu.h>
#include <qprogressbar.h>
#include <qfileinfo.h>
#include <qmessagebox.h>
#include <qdialog.h>
#include <qtextstream.h>
#include <qdir.h>
#include <qwhatsthis.h>
#include <qregexp.h>
+#include <qpainter.h>
+#include <qpaintdevicemetrics.h>
#include <klocale.h>
#include <kdebug.h>
#include <kiconloader.h>
#include <kglobal.h>
#include <libkdepim/kpimglobalprefs.h>
#include <libkcal/calendar.h>
#include <libkcal/calendarlocal.h>
#include <libkcal/icalformat.h>
#include <libkcal/vcalformat.h>
#include <libkcal/recurrence.h>
#include <libkcal/filestorage.h>
#include <libkdepim/categoryselectdialog.h>
#include <libkcal/kincidenceformatter.h>
#ifndef DESKTOP_VERSION
#include <qpe/qpeapplication.h>
#else
#include <qapplication.h>
#endif
#ifndef KORG_NOPRINTER
#include "calprinter.h"
#endif
#include "koglobals.h"
#include "koprefs.h"
#include "kfiledialog.h"
#include "kolistview.h"
+#include "koeventviewer.h"
class KOListViewWhatsThis :public QWhatsThis
{
public:
KOListViewWhatsThis( QWidget *wid, KOListView* view ) : QWhatsThis( wid ), _wid(wid),_view (view) { };
protected:
virtual QString text( const QPoint& p)
{
return _view->getWhatsThisText(p) ;
}
private:
QWidget* _wid;
KOListView * _view;
};
ListItemVisitor::ListItemVisitor(KOListViewItem *item, QDate date )
{
mItem = item;
mDate = date;
}
ListItemVisitor::~ListItemVisitor()
{
}
bool ListItemVisitor::visit(Event *e)
{
bool ok = false;
QString start, end;
QDate ds, de;
if ( e->doesRecur() ) {
ds = e->getNextOccurence( QDateTime( mDate, QTime(0,0,0)), &ok ).date();
if ( ok ) {
int days = e->dtStart().date().daysTo(e->dtEnd().date() );
start = KGlobal::locale()->formatDate(ds,true);
de = ds.addDays( days);
end = KGlobal::locale()->formatDate(de,true);
}
}
if ( ! ok ) {
start =e->dtStartDateStr();
end = e->dtEndDateStr();
@@ -235,97 +238,108 @@ KOListView::KOListView(Calendar *calendar, QWidget *parent,
const char *name)
: KOEventView(calendar, parent, name)
{
mActiveItem = 0;
mListView = new KOListViewListView(this);
mListView->addColumn(i18n("Summary"));
mListView->addColumn(i18n("Start Date"));
mListView->addColumn(i18n("Start Time"));
mListView->addColumn(i18n("End Date"));
mListView->addColumn(i18n("End Time"));
mListView->addColumn(i18n("Alarm")); // alarm set?
mListView->addColumn(i18n("Recurs")); // recurs?
mListView->addColumn(i18n("Due Date"));
mListView->addColumn(i18n("Due Time"));
mListView->addColumn(i18n("Cancelled"));
mListView->addColumn(i18n("Categories"));
mListView->setColumnAlignment(0,AlignLeft);
mListView->setColumnAlignment(1,AlignLeft);
mListView->setColumnAlignment(2,AlignHCenter);
mListView->setColumnAlignment(3,AlignLeft);
mListView->setColumnAlignment(4,AlignHCenter);
mListView->setColumnAlignment(5,AlignLeft);
mListView->setColumnAlignment(6,AlignLeft);
mListView->setColumnAlignment(7,AlignLeft);
mListView->setColumnAlignment(8,AlignLeft);
mListView->setColumnAlignment(9,AlignLeft);
mListView->setColumnAlignment(10,AlignLeft);
mListView->setColumnWidthMode(10, QListView::Manual);
mKOListViewWhatsThis = new KOListViewWhatsThis(mListView->viewport(),this);
int iii = 0;
for ( iii = 0; iii< 10 ; ++iii )
mListView->setColumnWidthMode( iii, QListView::Manual );
QBoxLayout *layoutTop = new QVBoxLayout(this);
layoutTop->addWidget(mListView);
mListView->setFont ( KOPrefs::instance()->mListViewFont );
mPopupMenu = eventPopup();
mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
i18n("Select all"),this,
SLOT(allSelection()),true);
mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
i18n("Deselect all"),this,
SLOT(clearSelection()),true);
mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
i18n("Delete all selected"),this,
SLOT(deleteAll()),true);
+#ifdef DESKTOP_VERSION
+ mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
+ i18n("Hide all selected"),this,
+ SLOT(hideAll()),true);
+#endif
+ mPopupMenu->insertSeparator();
+#ifdef DESKTOP_VERSION
+ mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
+ i18n("Print complete list"),this,
+ SLOT(printList()),true);
mPopupMenu->insertSeparator();
+#endif
QPopupMenu * exportPO = new QPopupMenu ( this );
mPopupMenu->insertItem( i18n("Export selected"), exportPO );
exportPO->insertItem( i18n("As iCal (ics) file..."),this,
SLOT(saveToFile()));
exportPO->insertItem( i18n("As vCal (vcs) file..."),this,
SLOT(saveToFileVCS()));
exportPO->insertItem( i18n("Journal/Details..."),this,
SLOT(saveDescriptionToFile()));
// mPopupMenu->insertSeparator();
mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
i18n("Add Categ. to selected..."),this,
SLOT(addCat()),true);
mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
i18n("Set Categ. for selected..."),this,
SLOT(setCat()),true);
//mPopupMenu->insertSeparator();
mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
i18n("Set alarm for selected..."),this,
SLOT(setAlarm()),true);
#ifndef DESKTOP_VERSION
mPopupMenu->insertSeparator();
mPopupMenu->addAdditionalItem(QIconSet(QPixmap()),
i18n("Beam selected via IR"),this,
SLOT(beamSelected()),true);
#endif
/*
mPopupMenu = new QPopupMenu;
mPopupMenu->insertItem(i18n("Edit Event"), this,
SLOT (editEvent()));
mPopupMenu->insertItem(SmallIcon("delete"), i18n("Delete Event"), this,
SLOT (deleteEvent()));
mPopupMenu->insertSeparator();
mPopupMenu->insertItem(i18n("Show Dates"), this,
SLOT(showDates()));
mPopupMenu->insertItem(i18n("Hide Dates"), this,
SLOT(hideDates()));
*/
QObject::connect(mListView,SIGNAL( newEvent()),
this,SIGNAL(signalNewEvent()));
QObject::connect(mListView,SIGNAL(doubleClicked(QListViewItem *)),
this,SLOT(defaultItemAction(QListViewItem *)));
QObject::connect(mListView,SIGNAL(rightButtonPressed( QListViewItem *,
const QPoint &, int )),
this,SLOT(popupMenu(QListViewItem *,const QPoint &,int)));
QObject::connect(mListView,SIGNAL(currentChanged(QListViewItem *)),
SLOT(processSelectionChange(QListViewItem *)));
@@ -677,96 +691,117 @@ void KOListView::writeToFile( bool iCal )
if ( fn.right( 4 ).lower() == ".vcs" ) {
fn = fn.left( fn.length() -3) + "ics";
}
} else {
if ( fn.right( 4 ).lower() == ".ics" ) {
fn = fn.left( fn.length() -3) + "vcs";
}
}
fn = KFileDialog::getSaveFileName( fn, i18n("Save filename"), this );
if ( fn == "" )
return;
QFileInfo info;
info.setFile( fn );
QString mes;
bool createbup = true;
if ( info. exists() ) {
mes = i18n("File already exists!\nOld file from:\n%1\nOverwrite?\n").arg (KGlobal::locale()->formatDateTime(info.lastModified (), true, false ) );
int result = QMessageBox::warning( this, i18n("KO/Pi: Warning!"),mes,
i18n("Overwrite!"), i18n("Cancel"), 0,
0, 1 );
if ( result != 0 ) {
createbup = false;
}
}
if ( createbup ) {
CalendarLocal cal;
cal.setTimeZoneId(KPimGlobalPrefs::instance()->mTimeZoneId);
Incidence *incidence = delSel.first();
while ( incidence ) {
cal.addIncidence( incidence->clone() );
incidence = delSel.next();
}
if ( iCal ) {
ICalFormat format;
format.save( &cal, fn );
} else {
VCalFormat format;
format.save( &cal, fn );
}
mes = i18n("KO/Pi:Saved %1").arg(fn );
KOPrefs::instance()->mLastSaveFile = fn;
topLevelWidget()->setCaption(mes);
}
}
QTimer::singleShot( 1, this, SLOT ( resetFocus() ) );
}
+void KOListView::hideAll()
+{
+ QPtrList<QListViewItem> delSel ;
+ QListViewItem *item = mListView->firstChild ();
+ while ( item ) {
+ if ( item->isSelected() ) {
+ delSel.append(item);
+ }
+ item = item->nextSibling();
+ }
+ item = delSel.first() ;
+ while ( item ) {
+ QListViewItem * del = item;
+ item = delSel.next();
+ delete del;
+ }
+}
+void KOListView::printList()
+{
+ mListView->printList();
+}
void KOListView::deleteAll()
{
int icount = 0;
QPtrList<Incidence> delSel ;
QListViewItem *item = mListView->firstChild ();
while ( item ) {
if ( item->isSelected() ) {
delSel.append(((KOListViewItem *)item)->data());
++icount;
}
item = item->nextSibling();
}
if ( icount ) {
Incidence *incidence = delSel.first();
Incidence *toDelete;
KOPrefs *p = KOPrefs::instance();
bool confirm = p->mConfirm;
QString mess;
mess = mess.sprintf( i18n("You have %d item(s) selected.\n"), icount );
if ( KMessageBox::Continue == KMessageBox::warningContinueCancel(this, mess + i18n("All selected items will be\npermanently deleted.\n(Deleting items will take\nsome time on a PDA)\n"), i18n("KO/Pi Confirmation"),i18n("Delete")) ) {
p->mConfirm = false;
int delCounter = 0;
QDialog dia ( this, "p-dialog", true );
QLabel lab (i18n("Close dialog to abort deletion!"), &dia );
QVBoxLayout lay( &dia );
lay.setMargin(7);
lay.setSpacing(7);
lay.addWidget( &lab);
QProgressBar bar( icount, &dia );
lay.addWidget( &bar);
int w = 220;
int h = 50;
int dw = QApplication::desktop()->width();
int dh = QApplication::desktop()->height();
dia.setGeometry( (dw-w)/2, (dh - h )/2 ,w,h );
//dia.resize( 240,50 );
dia.show();
while ( incidence ) {
bar.setProgress( delCounter );
mess = mess.sprintf( i18n("Deleting item %d ..."), ++delCounter );
dia.setCaption( mess );
qApp->processEvents();
toDelete = (incidence);
incidence = delSel.next();
emit deleteIncidenceSignal(toDelete );
if ( dia.result() != 0 )
@@ -1242,48 +1277,95 @@ void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
{
KListView::contentsMouseMoveEvent(e);
}
#endif
void KOListViewListView::popupMenu()
{
mPopupTimer->stop();
QMouseEvent* e = new QMouseEvent( QEvent::MouseButtonPress, mEventPos ,mEventGlobalPos, RightButton , RightButton );
QApplication::postEvent( this->viewport(), e );
}
void KOListViewListView::contentsMousePressEvent(QMouseEvent *e)
{
//qDebug("contentsMousePressEvent++++ %d %d", e->pos().y(), e->globalPos().y());
mYMousePos = mapToGlobal( (e->pos())).y();
if ( e->button() == LeftButton ) {
mPopupTimer->start( 600 );
mEventPos = contentsToViewport(e->pos());
mEventGlobalPos = e->globalPos();
}
KListView::contentsMousePressEvent( e );
if ( e->button() == RightButton ) {
QListViewItem* ci = currentItem();
//clearSelection();
if ( ci )
ci->setSelected( true );
}
}
void KOListViewListView::contentsMouseReleaseEvent(QMouseEvent *e)
{
mPopupTimer->stop();
KListView::contentsMouseReleaseEvent(e);
}
void KOListViewListView::contentsMouseMoveEvent(QMouseEvent *e)
{
// qDebug("contentsMouseMoveEv....... ");
// qDebug("start: %d current %d ",mYMousePos , mapToGlobal( (e->pos())).y() );
int diff = mYMousePos - mapToGlobal( (e->pos())).y();
if ( diff < 0 ) diff = -diff;
if ( diff > 15 )
mPopupTimer->stop();
else {
mEventPos = contentsToViewport(e->pos());
mEventGlobalPos = e->globalPos();
}
KListView::contentsMouseMoveEvent(e);
}
+#define protected public
+#include <qheader.h>
+#undef protected
+void KOListViewListView::printList()
+{
+#ifdef DESKTOP_VERSION
+ KOPrintPrefs pp ( this );
+ if (!pp.exec() )
+ return;
+ int scaleval = pp.printMode() ;
+
+ QPrinter printer;
+ if (!printer.setup() )
+ return;
+ clearSelection ();
+ QPainter p;
+ p.begin ( &printer );
+ QPaintDeviceMetrics m = QPaintDeviceMetrics ( &printer );
+ float dx, dy;
+ int wid = (m.width() * 9)/10;
+ dx = (float) wid/(float)contentsWidth ();
+ dy = (float)(m.height()) / (float)contentsHeight ();
+ float scale;
+ // scale to fit the width or height of the paper
+ if ( dx < dy )
+ scale = dx;
+ else
+ scale = dy;
+
+ p.translate( m.width()/10,m.width()/10 );
+ if ( scaleval == 2 || scaleval == 1 && scale < 1.0 ) {
+ p.scale( scale, scale );
+ }
+
+ int cou = header()->count();
+ int iii;
+ QRect rect ( 0,0,0, header()->height());
+ for ( iii = 0; iii < cou; ++iii ) {
+ rect.setLeft ( header()->sectionPos( iii ) );
+ rect.setRight ( header()->sectionPos( iii ) + header()->sectionSize (iii));
+ header()->paintSection ( & p, header()->mapToIndex (iii), rect );
+ }
+ p.translate( 0, header()->height());
+ drawContentsOffset ( &p, 0,0, 0,0, contentsWidth (), contentsHeight () );
+ p.end();
+#endif
+}