korganizer Library API Documentation

koincidencetooltip.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Requires the Qt and KDE widget libraries, available at no cost at 00005 http://www.troll.no and http://www.kde.org respectively 00006 00007 Copyright (c) 2003 00008 Reinhold Kainhofer <reinhold@kainhofer.com> 00009 00010 This program is free software; you can redistribute it and/or modify 00011 it under the terms of the GNU General Public License as published by 00012 the Free Software Foundation; either version 2 of the License, or 00013 (at your option) any later version. 00014 00015 This program is distributed in the hope that it will be useful, 00016 but WITHOUT ANY WARRANTY; without even the implied warranty of 00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00018 GNU General Public License for more details. 00019 00020 You should have received a copy of the GNU General Public License 00021 along with this program; if not, write to the Free Software 00022 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00023 */ 00024 00025 #include <libkcal/incidence.h> 00026 #include <libkcal/event.h> 00027 #include <libkcal/todo.h> 00028 #include <libkcal/journal.h> 00029 00030 #include <klocale.h> 00031 #include "koincidencetooltip.h" 00032 00038 void KOIncidenceToolTip::add ( QWidget * widget, Incidence *incidence, 00039 QToolTipGroup * group, const QString & longText ) 00040 { 00041 if ( !widget || !incidence ) return; 00042 QString tipText; 00043 ToolTipVisitor v; 00044 v.act( incidence, &tipText, true ); 00045 QToolTip::add(widget, tipText, group, longText); 00046 } 00047 00048 QString ToolTipVisitor::dateRangeText( Event*event ) 00049 { 00050 QString ret; 00051 QString tmp; 00052 if ( event->isMultiDay() ) { 00053 00054 tmp = "<br>" + i18n("Event start", "<i>From:</i>&nbsp;%1"); 00055 if (event->doesFloat()) 00056 ret += tmp.arg( event->dtStartDateStr().replace(" ", "&nbsp;") ); 00057 else 00058 ret += tmp.arg( event->dtStartStr().replace(" ", "&nbsp;") ); 00059 00060 tmp = "<br>" + i18n("<i>To:</i>&nbsp;%1"); 00061 if (event->doesFloat()) 00062 ret += tmp.arg( event->dtEndDateStr().replace(" ", "&nbsp;") ); 00063 else 00064 ret += tmp.arg( event->dtEndStr().replace(" ", "&nbsp;") ); 00065 00066 } else { 00067 00068 ret += "<br>"+i18n("<i>Date:</i>&nbsp;%1"). 00069 arg( event->dtStartDateStr().replace(" ", "&nbsp;") ); 00070 if ( !event->doesFloat() ) { 00071 tmp = "<br>" + i18n("time range for event, &nbsp; to prevent ugly line breaks", 00072 "<i>Time:</i>&nbsp;%1&nbsp;-&nbsp;%2"). 00073 arg( event->dtStartTimeStr().replace(" ", "&nbsp;") ). 00074 arg( event->dtEndTimeStr().replace(" ", "&nbsp;") ); 00075 ret += tmp; 00076 } 00077 00078 } 00079 return ret; 00080 } 00081 00082 QString ToolTipVisitor::dateRangeText( Todo*todo ) 00083 { 00084 QString ret; 00085 bool floats( todo->doesFloat() ); 00086 if (todo->hasStartDate()) 00087 // No need to add <i> here. This is separated issue and each line 00088 // is very visible on its own. On the other hand... Yes, I like it 00089 // italics here :) 00090 ret += "<br>" + i18n("<i>Start:</i>&nbsp;%1").arg( 00091 (floats) 00092 ?(todo->dtStartDateStr().replace(" ", "&nbsp;")) 00093 :(todo->dtStartStr().replace(" ", "&nbsp;")) ) ; 00094 if (todo->hasDueDate()) 00095 ret += "<br>" + i18n("<i>Due:</i>&nbsp;%1").arg( 00096 (floats) 00097 ?(todo->dtDueDateStr().replace(" ", "&nbsp;")) 00098 :(todo->dtDueStr().replace(" ", "&nbsp;")) ); 00099 if (todo->isCompleted()) 00100 ret += "<br>" + i18n("<i>Completed:</i>&nbsp;%1").arg( todo->completedStr().replace(" ", "&nbsp;") ); 00101 else 00102 ret += "<br>" + i18n("%1 % completed").arg(todo->percentComplete()); 00103 00104 return ret; 00105 } 00106 00107 QString ToolTipVisitor::dateRangeText( Journal* ) 00108 { 00109 QString ret; 00110 return ret; 00111 } 00112 00113 00114 bool ToolTipVisitor::visit( Event *event ) 00115 { 00116 QString dtRangeText( dateRangeText( event ) ); 00117 return generateToolTip( event, dtRangeText ); 00118 } 00119 00120 bool ToolTipVisitor::visit( Todo *todo ) 00121 { 00122 QString dtRangeText( dateRangeText( todo ) ); 00123 return generateToolTip( todo, dtRangeText ); 00124 } 00125 00126 bool ToolTipVisitor::visit( Journal *journal ) 00127 { 00128 QString dtRangeText( dateRangeText( journal ) ); 00129 return generateToolTip( journal, dtRangeText ); 00130 } 00131 00132 bool ToolTipVisitor::generateToolTip( Incidence* incidence, QString dtRangeText ) 00133 { 00134 QString tipText = "<qt><b>"+ incidence->summary().replace("\n", "<br>")+"</b>"; 00135 00136 tipText += dtRangeText; 00137 00138 if (!incidence->location().isEmpty()) { 00139 // Put Location: in italics 00140 tipText += "<br>"+i18n("<i>Location:</i>&nbsp;%1"). 00141 arg( incidence->location().replace("\n", "<br>") ); 00142 } 00143 if (!incidence->description().isEmpty()) { 00144 QString desc(incidence->description()); 00145 if (desc.length()>120) { 00146 desc = desc.left(120) + "..."; 00147 } 00148 tipText += "<br>----------<br>" + i18n("<i>Description:</i><br>") + desc.replace("\n", "<br>"); 00149 } 00150 tipText += "</qt>"; 00151 *mTipText = tipText; 00152 return true; 00153 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.2.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Jul 28 23:58:13 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003