summaryrefslogtreecommitdiffstats
path: root/ksysguard/gui/ksgrd/StyleEngine.cc
blob: ce3e3bd6bf426b1084f57e3db5922757c04f7176 (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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
    KSysGuard, the KDE System Guard

    Copyright (c) 1999 - 2001 Chris Schlaeger <cs@kde.org>

    This program is free software; you can redistribute it and/or
    modify it under the terms of version 2 of the GNU General Public
    License as published by the Free Software Foundation.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.

    KSysGuard is currently maintained by Chris Schlaeger <cs@kde.org>.
    Please do not commit any changes without consulting me first. Thanks!

*/

#include <tqimage.h>
#include <tqpushbutton.h>
#include <tqspinbox.h>

#include <tdeconfig.h>
#include <tdelocale.h>

#include "StyleSettings.h"

#include "StyleEngine.h"

using namespace KSGRD;

StyleEngine* KSGRD::Style;

StyleEngine::StyleEngine()
{
  mFirstForegroundColor = TQColor( 0x6894c9 );  // light blue
  mSecondForegroundColor = TQColor( 0x6894c9 ); // light blue
  mAlarmColor = TQColor( 255, 0, 0 );
  mBackgroundColor = TQColor( 0x313031 );       // almost black
  mFontSize = 9;

  mSensorColors.append( TQColor( 0x1889ff ) );  // soft blue
  mSensorColors.append( TQColor( 0xff7f08 ) );  // reddish
  mSensorColors.append( TQColor( 0xffeb14 ) );  // bright yellow

  uint v = 0x00ff00;
  for ( uint i = mSensorColors.count(); i < 32; ++i ) {
    v = ( ( ( v + 82 ) & 0xff ) << 23 ) | ( v >> 8 );
    mSensorColors.append( TQColor( v & 0xff, ( v >> 16 ) & 0xff, ( v >> 8 ) & 0xff ) );
  }
}

StyleEngine::~StyleEngine()
{
}

void StyleEngine::readProperties( TDEConfig *cfg )
{
  mFirstForegroundColor = cfg->readColorEntry( "fgColor1", &mFirstForegroundColor );
  mSecondForegroundColor = cfg->readColorEntry( "fgColor2", &mSecondForegroundColor );
  mAlarmColor = cfg->readColorEntry( "alarmColor", &mAlarmColor );
  mBackgroundColor = cfg->readColorEntry( "backgroundColor", &mBackgroundColor );
  mFontSize = cfg->readNumEntry( "fontSize", mFontSize );

  TQStringList list = cfg->readListEntry( "sensorColors" );
  if ( !list.isEmpty() ) {
    mSensorColors.clear();
    TQStringList::Iterator it;
    for ( it = list.begin(); it != list.end(); ++it )
      mSensorColors.append( TQColor( *it ) );
  }
}

void StyleEngine::saveProperties( TDEConfig *cfg )
{
  cfg->writeEntry( "fgColor1", mFirstForegroundColor );
  cfg->writeEntry( "fgColor2", mSecondForegroundColor );
  cfg->writeEntry( "alarmColor", mAlarmColor );
  cfg->writeEntry( "backgroundColor", mBackgroundColor );
  cfg->writeEntry( "fontSize", mFontSize );

  TQStringList list;
  TQValueList<TQColor>::Iterator it;
  for ( it = mSensorColors.begin(); it != mSensorColors.end(); ++it )
    list.append( (*it).name() );

  cfg->writeEntry( "sensorColors", list );
}

const TQColor &StyleEngine::firstForegroundColor() const
{
  return mFirstForegroundColor;
}

const TQColor &StyleEngine::secondForegroundColor() const
{
  return mSecondForegroundColor;
}

const TQColor &StyleEngine::alarmColor() const
{
  return mAlarmColor;
}

const TQColor &StyleEngine::backgroundColor() const
{
  return mBackgroundColor;
}

uint StyleEngine::fontSize() const
{
  return mFontSize;
}

const TQColor& StyleEngine::sensorColor( uint pos )
{
  static TQColor dummy;

  if ( pos < mSensorColors.count() )
    return *mSensorColors.at( pos );
  else
    return dummy;
}

uint StyleEngine::numSensorColors() const
{
  return mSensorColors.count();
}

void StyleEngine::configure()
{
  mSettingsDialog = new StyleSettings( 0 );

  mSettingsDialog->setFirstForegroundColor( mFirstForegroundColor );
	mSettingsDialog->setSecondForegroundColor( mSecondForegroundColor );
  mSettingsDialog->setAlarmColor( mAlarmColor );
  mSettingsDialog->setBackgroundColor( mBackgroundColor );
  mSettingsDialog->setFontSize( mFontSize );
  mSettingsDialog->setSensorColors( mSensorColors );

  connect( mSettingsDialog, TQT_SIGNAL( applyClicked() ),
           this, TQT_SLOT( applyToWorksheet() ) );

  if ( mSettingsDialog->exec() )
    apply();

  delete mSettingsDialog;
  mSettingsDialog = 0;
}

void StyleEngine::applyToWorksheet()
{
  apply();
  emit applyStyleToWorksheet();
}

void StyleEngine::apply()
{
  if ( !mSettingsDialog )
    return;

  mFirstForegroundColor = mSettingsDialog->firstForegroundColor();
  mSecondForegroundColor = mSettingsDialog->secondForegroundColor();
  mAlarmColor = mSettingsDialog->alarmColor();
  mBackgroundColor = mSettingsDialog->backgroundColor();
  mFontSize = mSettingsDialog->fontSize();

  mSensorColors = mSettingsDialog->sensorColors();
}

#include "StyleEngine.moc"