summaryrefslogtreecommitdiffstats
path: root/ksplashml/themeengine/redmond/previewredmond.cpp
blob: 3bfb8020366ea84a44bbe12c39200561579a6a2b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/***************************************************************************
 *   Copyright Brian Ledbetter 2001-2003 <brian@shadowcom.net>             *
 *   Copyright Ravikiran Rajagopal 2003                                    *
 *   ravi@ee.eng.ohio-state.edu                                            *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License (version 2) as   *
 *   published by the Free Software Foundation. (The original KSplash/ML   *
 *   codebase (upto version 0.95.3) is BSD-licensed.)                      *
 *                                                                         *
 ***************************************************************************/

#include <klocale.h>

#include <tqpainter.h>
#include <tqpixmap.h>
#include <tqwidget.h>

#include "previewredmond.h"
#include "previewredmond.moc"
/*
 * PreviewRedmond::PreviewRedmond(): Constructor. Set up some basic
 * things.
 */
PreviewRedmond::PreviewRedmond( TQWidget* parent )
    :TQWidget( parent ),

    /* Using direct constructors to prevent memory blit. */
    m_welcomeString (i18n("Welcome")),
    m_userString (i18n("(Your Name)")),

    m_welcomeFont (TQFont( "Arial", 16, TQFont::Bold )),
    m_userFont (TQFont( "Arial", 16 )),
    m_statusFont (TQFont( "Arial", 12, TQFont::Bold )),

    m_welcomeColor (Qt::white),
    m_welcomeShadowColor (Qt::darkGray),
    m_userColor (Qt::darkGray),
    m_statusColor (Qt::white),

    m_icon (DesktopIcon("kmenu")),

    m_showWelcomeString (true),
    m_showUserString (true),
    m_showUserIcon (true),
    m_showStatusString (true)
{
  _updateCache();
}

void PreviewRedmond::paintEvent( TQPaintEvent* pe )
{
  TQPainter p;
  p.begin( this );
  p.drawPixmap( pe->rect(), m_cache );
  p.end();
}

void PreviewRedmond::resizeEvent( TQResizeEvent *re )
{
  TQWidget::resizeEvent( re );
  _updateCache();
}

// PreviewRedmond::_updateCache(): Based on our current settings, we need
// to adjust our cached image. We'll slick it and create a new QPixmap
// from size(), just to be sure we're not missing anything.
void PreviewRedmond::_updateCache()
{
  m_cache = TQPixmap( size() );
  TQPainter p;
  p.begin( &m_cache );

  p.fillRect( rect(), Qt::gray );

  m_welcomeFont.setItalic( true );
  p.setFont( m_welcomeFont );

  TQPoint welcomeTextPos( rect().width()/2 - p.fontMetrics().width( m_welcomeString ),
    rect().height()/2 + p.fontMetrics().height()/2 );

  if( m_showWelcomeString )
  {
    p.setPen( m_welcomeShadowColor );
    p.drawText( welcomeTextPos.x()+2, welcomeTextPos.y()+2, m_welcomeString );
    p.setPen( m_welcomeColor );
    p.drawText( welcomeTextPos, m_welcomeString );
  }

  if( m_showUserString )
  {
    p.setPen( m_userColor );
    p.setFont( m_userFont );
    TQPoint userTextPos( rect().width()/2 + m_icon.width() + 20,
      rect().height()/2 + p.fontMetrics().height()/2 );
    p.drawText( userTextPos, m_userString );
  }

  if( m_showUserIcon )
    p.drawPixmap( rect().width()/2 + 10, rect().height()/2, m_icon );

  if( m_showStatusString )
  {
    TQPoint statusTextPos( rect().width()/2 + m_icon.width() + 20,
      rect().height()/2 + (int)(p.fontMetrics().height()*0.85) + 15 );
    p.setPen( m_statusColor );
    p.setFont( m_statusFont );
    p.drawText( statusTextPos, i18n("Starting KDE...") );
  }

  p.end();
  update( rect() );
}