korganizer Library API Documentation

koincidencetooltip.cpp

00001 /* 00002 This file is part of KOrganizer. 00003 00004 Copyright (c) 2003 Reinhold Kainhofer <reinhold@kainhofer.com> 00005 00006 This program is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 2 of the License, or 00009 (at your option) any later version. 00010 00011 This program is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program; if not, write to the Free Software 00018 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00019 00020 As a special exception, permission is given to link this program 00021 with any edition of Qt, and distribute the resulting executable, 00022 without including the source code for Qt in the source distribution. 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*journal ) 00108 { 00109 QString ret; 00110 if (journal->dtStart().isValid() ) { 00111 ret += "<br>" + i18n("<i>Date:</i>&nbsp;%1").arg( journal->dtStartDateStr( false ) ); 00112 } 00113 return ret; 00114 } 00115 00116 00117 bool ToolTipVisitor::visit( Event *event ) 00118 { 00119 QString dtRangeText( dateRangeText( event ) ); 00120 return generateToolTip( event, dtRangeText ); 00121 } 00122 00123 bool ToolTipVisitor::visit( Todo *todo ) 00124 { 00125 QString dtRangeText( dateRangeText( todo ) ); 00126 return generateToolTip( todo, dtRangeText ); 00127 } 00128 00129 bool ToolTipVisitor::visit( Journal *journal ) 00130 { 00131 QString dtRangeText( dateRangeText( journal ) ); 00132 return generateToolTip( journal, dtRangeText ); 00133 } 00134 00135 bool ToolTipVisitor::generateToolTip( Incidence* incidence, QString dtRangeText ) 00136 { 00137 QString tipText = "<qt><b>"+ incidence->summary().replace("\n", "<br>")+"</b>"; 00138 00139 tipText += dtRangeText; 00140 00141 if (!incidence->location().isEmpty()) { 00142 // Put Location: in italics 00143 tipText += "<br>"+i18n("<i>Location:</i>&nbsp;%1"). 00144 arg( incidence->location().replace("\n", "<br>") ); 00145 } 00146 if (!incidence->description().isEmpty()) { 00147 QString desc(incidence->description()); 00148 if (desc.length()>120) { 00149 desc = desc.left(120) + "..."; 00150 } 00151 tipText += "<br>----------<br>" + i18n("<i>Description:</i><br>") + desc.replace("\n", "<br>"); 00152 } 00153 tipText += "</qt>"; 00154 *mTipText = tipText; 00155 return true; 00156 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.0.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Fri Oct 1 15:19:31 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003