summaryrefslogtreecommitdiffstats
path: root/yakuake/src/title_bar.cpp
blob: 1be43026a97173a7635eda2e6bd0fd3d382936d3 (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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/*
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.
*/

/*
  Copyright (C) 2005 Francois Chazal <neptune3k@free.fr>
  Copyright (C) 2006-2007 Eike Hein <hein@kde.org>
*/


#include "title_bar.h"
#include "title_bar.moc"

#include <tqtooltip.h>
#include <tqwhatsthis.h>

#include <tdelocale.h>


TitleBar::TitleBar(TQWidget * parent, const char * name, const TQString & skin) : TQWidget(parent, name)
{
    TQWhatsThis::add(this, i18n("The title bar displays the session title if available."));

    loadSkin(skin);

    connect(focus_button, TQ_SIGNAL(toggled(bool)), parent, TQ_SLOT(slotSetFocusPolicy(bool)));
    connect(quit_button, TQ_SIGNAL(clicked()), parent, TQ_SLOT(close()));
}

TitleBar::~TitleBar()
{
    delete config_button;
    delete focus_button;
    delete quit_button;
}

TQRegion& TitleBar::getWidgetMask()
{
    return mask;
}

void TitleBar::setTitleText(const TQString& title)
{
    if (title == title_text)
        return;

    title_text = title;
    repaint();
}

void TitleBar::setFocusButtonEnabled(bool enable)
{
    focus_button->setToggled(enable);
}

void TitleBar::setConfigurationMenu(TDEPopupMenu* menu)
{
    config_button->setPopupMenu(menu);
}

void TitleBar::paintEvent(TQPaintEvent*)
{
    TQPainter painter(this);
    TQFont font(painter.font());

    painter.drawTiledPixmap(0, 0, width(), height(), back_image);

    painter.drawPixmap(0, 0, left_corner);
    painter.drawPixmap(width() - right_corner.width(), 0, right_corner);

    // Add " - " divider between title and skin text.
    TQString title_postfix(skin_text);
    if (!title_postfix.isEmpty() && !title_text.isEmpty())
        title_postfix.prepend(" - ");

    font.setBold(true);
    painter.setFont(font);
    painter.setPen(text_color);
    painter.drawText(text_position, title_text + title_postfix);

    painter.end();
}

void TitleBar::resizeEvent(TQResizeEvent *)
{
    updateWidgetMask();

    config_button->move(width() - config_position.x(), config_position.y());
    focus_button->move(width() - focus_position.x(), focus_position.y());
    quit_button->move(width() - quit_position.x(), quit_position.y());
}

void TitleBar::loadSkin(const TQString& skin)
{
    focus_button = new ImageButton(this, "Focus button");
    focus_button->setToggleButton(true);
    TQToolTip::add(focus_button, i18n("Keep open when focus is lost"));

    config_button = new ImageButton(this, "Configuration button");
    TQToolTip::add(config_button, i18n("Open Menu"));

    quit_button = new ImageButton(this, "Quit button");
    TQToolTip::add(quit_button, i18n("Quit"));

    setPixmaps(skin);

    resize(width(), back_image.height());
}

void TitleBar::reloadSkin(const TQString& skin)
{
    setPixmaps(skin);

    resize(width(), back_image.height());

    config_button->move(width() - config_position.x(), config_position.y());
    focus_button->move(width() - focus_position.x(), focus_position.y());
    quit_button->move(width() - quit_position.x(), quit_position.y());

    updateWidgetMask();

    repaint();
}

void TitleBar::setPixmaps(const TQString& skin)
{
    /* Initialize the skin objects. */

    TQUrl url(locate("appdata", skin + "/title.skin"));
    TDEConfig config(url.path());

    // Load the text information.
    config.setGroup("Text");

    skin_text = config.readEntry("text", 0);

    text_color.setRgb(config.readNumEntry("red", 0),
                      config.readNumEntry("green", 0),
                      config.readNumEntry("blue", 0));

    text_position.setX(config.readNumEntry("x", 0));
    text_position.setY(config.readNumEntry("y", 0));

    // Load the background pixmaps.
    config.setGroup("Background");

    back_image.load(url.dirPath() + config.readEntry("back_image", ""));
    left_corner.load(url.dirPath() + config.readEntry("left_corner", ""));
    right_corner.load(url.dirPath() + config.readEntry("right_corner", ""));

    // Load the stay button.
    config.setGroup("FocusButton");

    focus_position.setX(config.readNumEntry("x", 0));
    focus_position.setY(config.readNumEntry("y", 0));
    focus_button->setUpPixmap(url.dirPath() + config.readEntry("up_image", ""), true);
    focus_button->setOverPixmap(url.dirPath() + config.readEntry("over_image", ""));
    focus_button->setDownPixmap(url.dirPath() + config.readEntry("down_image", ""));

    // Load the configuration button.
    config.setGroup("ConfigButton");

    config_position.setX(config.readNumEntry("x", 0));
    config_position.setY(config.readNumEntry("y", 0));
    config_button->setUpPixmap(url.dirPath() + config.readEntry("up_image", ""), true);
    config_button->setOverPixmap(url.dirPath() + config.readEntry("over_image", ""));
    config_button->setDownPixmap(url.dirPath() + config.readEntry("down_image", ""));

    // Load the quit button.
    config.setGroup("QuitButton");

    quit_position.setX(config.readNumEntry("x", 0));
    quit_position.setY(config.readNumEntry("y", 0));
    quit_button->setUpPixmap(url.dirPath() + config.readEntry("up_image", ""), true);
    quit_button->setOverPixmap(url.dirPath() + config.readEntry("over_image", ""));
    quit_button->setDownPixmap(url.dirPath() + config.readEntry("down_image", ""));
}

void TitleBar::updateWidgetMask()
{
    TQRegion temp_mask;

    mask = TQRegion(*left_corner.mask());
    mask += TQRegion(TQRect(TQPoint(left_corner.width(), 0), TQPoint(width() - right_corner.width() - 1, height() - 1)));

    temp_mask = TQRegion(*right_corner.mask());
    temp_mask.translate(width() - right_corner.width(), 0);
    mask += temp_mask;
}