• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdesdk API Reference
  • KDE Home
  • Contact Us
 

okteta

  • sources
  • kde-4.12
  • kdesdk
  • okteta
  • libs
  • framesprint
headerfooterframerenderer.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Okteta Kasten module, made within the KDE community.
3 
4  Copyright 2007 Friedrich W. H. Kossebau <kossebau@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "headerfooterframerenderer.h"
24 
25 // KDE
26 #include <KLocale>
27 #include <KGlobal>
28 #include <KUser>
29 // Qt
30 #include <QtCore/QHash>
31 #include <QtCore/QDateTime>
32 #include <QtGui/QPainter>
33 #include <QtGui/QFontMetrics>
34 
35 
36 HeaderFooterFrameRenderer::HeaderFooterFrameRenderer( const PrintInfo* info )
37  : mInfo( info ),
38  mHeight( 0 ), mWidth( 0 ), mBoxStyle( NoBox ), mLineWidth( 1 ), mBoxMargin( 6 ),
39  mBgColor( Qt::lightGray ), mFgColor( Qt::black ), mGloballyReplacedTextList()
40 {
41  mOriginalTextList << QString() << QString() << QString();
42  calculateHeight();
43 }
44 
45 int HeaderFooterFrameRenderer::height() const { return mHeight; }
46 int HeaderFooterFrameRenderer::width() const { return mWidth; }
47 
48 void HeaderFooterFrameRenderer::setWidth( int width ) { mWidth = width; }
49 
50 void HeaderFooterFrameRenderer::setTexts( const QString &leftText, const QString &centerText, const QString &rightText )
51 {
52  mOriginalTextList.clear();
53  mOriginalTextList << leftText << centerText << rightText;
54 }
55 
56 void HeaderFooterFrameRenderer::setBoxStyle( int boxStyle )
57 {
58  if( mBoxStyle == boxStyle )
59  return;
60  mBoxStyle = boxStyle;
61  calculateHeight();
62 }
63 
64 void HeaderFooterFrameRenderer::calculateHeight()
65 {
66  const QFontMetrics fontMetrics( mFont );
67 
68  mHeight = fontMetrics.height();
69 
70 // const bool hasSpaceAbove = ( mBoxStyle & (BackgroundDrawn|LineAbove) );
71 // const bool hasSpacedBelow = ( mBoxStyle & (BackgroundDrawn|LineBelow) );
72 // if( !(hasSpaceAbove||hasSpacedBelow) )
73  mHeight += fontMetrics.leading();
74 // else
75 // {
76 // if( hasSpaceAbove )
77 // {
78 // mHeight += mBoxMargin * 2;
79 //
80 // }
81 // }
82 }
83 
84 void HeaderFooterFrameRenderer::prepare()
85 {
86  const QDateTime dateTime = QDateTime::currentDateTime();
87  const KUser user( KUser::UseRealUserID );
88  const KUrl url = mInfo->url();
89 
90  // create list of replacements
91  QHash<char,QString> tagReplacements;
92 
93  tagReplacements['d'] = KGlobal::locale()->formatDateTime( dateTime, KLocale::ShortDate );
94  tagReplacements['D'] = KGlobal::locale()->formatDateTime( dateTime, KLocale::LongDate );
95  tagReplacements['h'] = KGlobal::locale()->formatTime( dateTime.time(), false );
96  tagReplacements['y'] = KGlobal::locale()->formatDate( dateTime.date(), KLocale::ShortDate );
97  tagReplacements['Y'] = KGlobal::locale()->formatDate( dateTime.date(), KLocale::LongDate );
98  tagReplacements['u'] = user.loginName();
99  tagReplacements['U'] = user.property( KUser::FullName ).toString();
100 // tagReplacements['f'] = isSelection ? i18n("(Selection of) %1", url.fileName()) : url.fileName();
101  tagReplacements['f'] = url.fileName();
102  tagReplacements['F'] = url.prettyUrl();
103  tagReplacements['P'] = QString::number( mInfo->noOfPages() );
104 
105  // create text with globally replaced tags
106  const int sizeOfTag = 2;
107  QRegExp tagsPattern( QLatin1String("%([dDhyYuUfFP])") );
108 
109  mGloballyReplacedTextList.clear();
110 
111  for( int i=0; i<3; ++i )
112  {
113  QString text = mOriginalTextList.at( i );
114  int pos = 0;
115  while( true )
116  {
117  pos = tagsPattern.indexIn( text, pos );
118  if( pos < 0 )
119  break;
120  QString replacement = tagReplacements[text[pos+1].toLatin1()];
121  text.replace( (uint)pos, sizeOfTag, replacement );
122  pos += replacement.length();
123  }
124  mGloballyReplacedTextList << text;
125  }
126 }
127 
128 void HeaderFooterFrameRenderer::renderFrame( QPainter *painter, int frameIndex )
129 {
130  painter->setPen( mFgColor );
131  painter->setFont( mFont );
132 // if( mBoxStyle & BackgroundDrawn )
133 // painter->fillRect( 0, 0, mWidth, mHeight, mBgColor );
134 
135  const bool isTextFramed = false;//( mBoxStyle & (Box|BackgroundDrawn) );
136 
137  const int horizontalAlign[3] = { Qt::AlignLeft, Qt::AlignHCenter, Qt::AlignRight };
138  int verticalAlign = isTextFramed ? Qt::AlignVCenter : Qt::AlignTop;
139  int margin = 0;//( mBoxStyle & (mBoxDrawn || mBackgroundDrawn ) ? mBoxMargin : 0;
140 // if ( mBoxStyle & LinesAtSide )
141 // margin += mLineWidth;
142  const int rightEnd = mWidth - (margin*2);
143 
144  for( int i=0; i<3; i++ )
145  {
146  QString text = mGloballyReplacedTextList[i];
147  // substitute locally
148  const QString pageNumberTag = QLatin1String( "%p" );
149  if( text.indexOf(pageNumberTag) != -1 )
150  text.replace( pageNumberTag, QString::number(frameIndex+1) ); //TODO: frameIndex != pageNumber in general
151  int align = verticalAlign | horizontalAlign[i];
152 
153  painter->drawText( margin, 0, rightEnd, mHeight, align, text );
154  }
155 // if ( !isTextFramed )
156  {
157 // painter->drawLine( 0, mHeight-mLineWidth, mWidth, mHeight-mLineWidth );
158 // painter->drawLine( 0, maxHeight + mBoxMargin - 1, headerWidth, maxHeight + mBoxMargin - 1 );
159 // painter->drawRect( 0, 0, pdmWidth, pdmHeight);
160 // paint.drawLine(0, headerHeight, headerWidth, headerHeight);
161  }
162 }
163 
164 HeaderFooterFrameRenderer::~HeaderFooterFrameRenderer() {}
HeaderFooterFrameRenderer::mFont
QFont mFont
Definition: headerfooterframerenderer.h:106
headerfooterframerenderer.h
PrintInfo::url
KUrl url() const
Definition: headerfooterframerenderer.h:52
HeaderFooterFrameRenderer::prepare
virtual void prepare()
painting will start, fix all things like Time and Data
Definition: headerfooterframerenderer.cpp:84
HeaderFooterFrameRenderer::calculateHeight
void calculateHeight()
Definition: headerfooterframerenderer.cpp:64
HeaderFooterFrameRenderer::mGloballyReplacedTextList
QStringList mGloballyReplacedTextList
Definition: headerfooterframerenderer.h:109
HeaderFooterFrameRenderer::setBoxStyle
void setBoxStyle(int boxStyle)
Definition: headerfooterframerenderer.cpp:56
HeaderFooterFrameRenderer::setTexts
void setTexts(const QString &leftText, const QString &centerText, const QString &rightText)
Definition: headerfooterframerenderer.cpp:50
HeaderFooterFrameRenderer::HeaderFooterFrameRenderer
HeaderFooterFrameRenderer(const PrintInfo *info)
Definition: headerfooterframerenderer.cpp:36
AbstractFrameRenderer::pos
QPoint pos() const
Definition: abstractframerenderer.cpp:43
HeaderFooterFrameRenderer::mBoxStyle
int mBoxStyle
Definition: headerfooterframerenderer.h:100
HeaderFooterFrameRenderer::mWidth
int mWidth
Definition: headerfooterframerenderer.h:98
HeaderFooterFrameRenderer::mInfo
const PrintInfo * mInfo
Definition: headerfooterframerenderer.h:95
HeaderFooterFrameRenderer::height
virtual int height() const
Definition: headerfooterframerenderer.cpp:45
HeaderFooterFrameRenderer::setWidth
void setWidth(int width)
Definition: headerfooterframerenderer.cpp:48
HeaderFooterFrameRenderer::width
virtual int width() const
Definition: headerfooterframerenderer.cpp:46
HeaderFooterFrameRenderer::mHeight
int mHeight
Definition: headerfooterframerenderer.h:97
HeaderFooterFrameRenderer::~HeaderFooterFrameRenderer
virtual ~HeaderFooterFrameRenderer()
Definition: headerfooterframerenderer.cpp:164
PrintInfo
Definition: headerfooterframerenderer.h:37
HeaderFooterFrameRenderer::mFgColor
QColor mFgColor
Definition: headerfooterframerenderer.h:105
PrintInfo::noOfPages
int noOfPages() const
Definition: headerfooterframerenderer.h:53
HeaderFooterFrameRenderer::mOriginalTextList
QStringList mOriginalTextList
Definition: headerfooterframerenderer.h:108
HeaderFooterFrameRenderer::renderFrame
virtual void renderFrame(QPainter *painter, int frameIndex)
Definition: headerfooterframerenderer.cpp:128
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 23:04:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

okteta

Skip menu "okteta"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdesdk API Reference

Skip menu "kdesdk API Reference"
  • kapptemplate
  • kcachegrind
  • kompare
  • lokalize
  • okteta
  • umbrello
  •   umbrello

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal