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 #include "koagendaitem.h"
00033 #include "kolistview.h"
00034 #include "komonthview.h"
00035 #include "kotodoviewitem.h"
00036 
00037 // explicit instantiations
00038 template class KOIncidenceToolTip<KOAgendaItem>;
00039 template class ToolTipVisitor<KOAgendaItem>;
00040 template class ToolTipVisitor<KOListViewItem>;
00041 template class ToolTipVisitor<MonthViewItem>;
00042 template class ToolTipVisitor<KOTodoViewItem>;
00043 
00049 /*
00050  template<class T>
00051 void KOIncidenceToolTip<T>::add ( T* item,
00052         QToolTipGroup * group, const QString & longText )
00053 {
00054 }
00055 
00056 */
00057 
00058 template<class T>
00059 QString ToolTipVisitor<T>::dateRangeText( Event*event )
00060 {
00061   QString ret;
00062   QString tmp;
00063   if ( event->isMultiDay() ) {
00064 
00065     tmp = "<br>" + i18n("Event start", "<i>From:</i>&nbsp;%1");
00066     if (event->doesFloat())
00067       ret += tmp.arg( event->dtStartDateStr().replace(" ", "&nbsp;") );
00068     else
00069       ret += tmp.arg( event->dtStartStr().replace(" ", "&nbsp;") );
00070 
00071     tmp = "<br>" + i18n("<i>To:</i>&nbsp;%1");
00072     if (event->doesFloat())
00073       ret += tmp.arg( event->dtEndDateStr().replace(" ", "&nbsp;") );
00074     else
00075       ret += tmp.arg( event->dtEndStr().replace(" ", "&nbsp;") );
00076 
00077   } else {
00078     ret += "<br>"+i18n("<i>Date:</i>&nbsp;");
00079     if ( event->doesRecur() ) {
00080       ret += KGlobal::locale()->formatDate( mItem->itemDate(), true );
00081     } else {
00082       ret += event->dtStartDateStr().replace(" ", "&nbsp;");
00083     }
00084     if ( !event->doesFloat() ) {
00085       tmp = "<br>" + i18n("time range for event, &nbsp; to prevent ugly line breaks",
00086         "<i>Time:</i>&nbsp;%1&nbsp;-&nbsp;%2").
00087         arg( event->dtStartTimeStr().replace(" ", "&nbsp;") ).
00088         arg( event->dtEndTimeStr().replace(" ", "&nbsp;") );
00089       ret += tmp;
00090     }
00091 
00092   }
00093   return ret;
00094 }
00095 
00096 template<class T>
00097 QString ToolTipVisitor<T>::dateRangeText( Todo*todo )
00098 {
00099   QString ret;
00100   bool floats( todo->doesFloat() );
00101   if (todo->hasStartDate())
00102     // No need to add <i> here. This is separated issue and each line
00103     // is very visible on its own. On the other hand... Yes, I like it
00104     // italics here :)
00105     ret += "<br>" + i18n("<i>Start:</i>&nbsp;%1").arg(
00106       (floats)
00107         ?(todo->dtStartDateStr().replace(" ", "&nbsp;"))
00108         :(todo->dtStartStr().replace(" ", "&nbsp;")) ) ;
00109   if (todo->hasDueDate())
00110     ret += "<br>" + i18n("<i>Due:</i>&nbsp;%1").arg(
00111       (floats)
00112         ?(todo->dtDueDateStr().replace(" ", "&nbsp;"))
00113         :(todo->dtDueStr().replace(" ", "&nbsp;")) );
00114   if (todo->isCompleted())
00115     ret += "<br>" + i18n("<i>Completed:</i>&nbsp;%1").arg( todo->completedStr().replace(" ", "&nbsp;") );
00116   else
00117     ret += "<br>" + i18n("%1 % completed").arg(todo->percentComplete());
00118 
00119   return ret;
00120 }
00121 
00122 template<class T>
00123 QString ToolTipVisitor<T>::dateRangeText( Journal*journal )
00124 {
00125   QString ret;
00126   if (journal->dtStart().isValid() ) {
00127     ret += "<br>" + i18n("<i>Date:</i>&nbsp;%1").arg( journal->dtStartDateStr( false ) );
00128   }
00129   return ret;
00130 }
00131 
00132 
00133 template<class T>
00134 bool ToolTipVisitor<T>::visit( Event *event )
00135 {
00136   QString dtRangeText( dateRangeText( event ) );
00137   return generateToolTip( event, dtRangeText  );
00138 }
00139 
00140 template<class T>
00141 bool ToolTipVisitor<T>::visit( Todo *todo )
00142 {
00143   QString dtRangeText( dateRangeText( todo ) );
00144   return generateToolTip( todo, dtRangeText  );
00145 }
00146 
00147 template<class T>
00148 bool ToolTipVisitor<T>::visit( Journal *journal )
00149 {
00150   QString dtRangeText( dateRangeText( journal ) );
00151   return generateToolTip( journal, dtRangeText  );
00152 }
00153 
00154 template<class T>
00155 bool ToolTipVisitor<T>::generateToolTip( Incidence* incidence, QString dtRangeText )
00156 {
00157   QString tipText = "<qt><b>"+ incidence->summary().replace("\n", "<br>")+"</b>";
00158 
00159   tipText += dtRangeText;
00160 
00161   if (!incidence->location().isEmpty()) {
00162     // Put Location: in italics
00163     tipText += "<br>"+i18n("<i>Location:</i>&nbsp;%1").
00164       arg( incidence->location().replace("\n", "<br>") );
00165   }
00166   if (!incidence->description().isEmpty()) {
00167     QString desc(incidence->description());
00168     if (desc.length()>120) {
00169       desc = desc.left(120) + "...";
00170     }
00171     tipText += "<br>----------<br>" + i18n("<i>Description:</i><br>") + desc.replace("\n", "<br>");
00172   }
00173   tipText += "</qt>";
00174   *mTipText = tipText;
00175   return true;
00176 }
KDE Logo
This file is part of the documentation for korganizer Library Version 3.3.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Thu Aug 2 09:56:05 2007 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003