1
/***************************************************************************
2
* Project TUPI: Magia 2D *
3
* Project Contact: info@maefloresta.com *
4
* Project Website: http://www.maefloresta.com *
5
* Project Leader: Gustav Gonzalez <info@maefloresta.com> *
9
* Gustavo Gonzalez / xtingray *
20
* Copyright (C) 2010 Gustav Gonzalez - http://www.maefloresta.com *
22
* This program is free software; you can redistribute it and/or modify *
23
* it under the terms of the GNU General Public License as published by *
24
* the Free Software Foundation; either version 3 of the License, or *
25
* (at your option) any later version. *
27
* This program is distributed in the hope that it will be useful, *
28
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
29
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
30
* GNU General Public License for more details. *
32
* You should have received a copy of the GNU General Public License *
33
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
34
***************************************************************************/
36
#include "tupexposureheader.h"
38
#include <QHeaderView>
40
#include <QStyleOptionButton>
43
#include <QItemDelegate>
45
#include <QMouseEvent>
49
#include <tupglobal.h>
62
* @author Jorge Cuadrado
65
TupExposureHeader::TupExposureHeader(QWidget * parent) : QHeaderView(Qt::Horizontal, parent), m_sectionEdited(-1),
66
m_blockSectionMoved(false)
70
//SQA: Disabled while layers movability is enhanced
73
connect(this, SIGNAL(sectionDoubleClicked(int)), this, SLOT(showEditorName(int)));
75
m_editor = new QLineEdit(this);
76
m_editor->setFocusPolicy(Qt::ClickFocus);
77
m_editor->setInputMask("");
78
connect(m_editor, SIGNAL(editingFinished()), this, SLOT(hideEditorName()));
82
TupExposureHeader::~TupExposureHeader()
86
void TupExposureHeader::emitVisibilityChanged(int section)
88
emit visibilityChanged(visualIndex(section), !m_layers[section].isVisible);
91
void TupExposureHeader::setVisibilityChanged(int layerIndex, bool visibility)
93
// Q_UNUSED(visibility);
94
// FIXME: in tupexpousertable.cpp visibility or !m_layers[logicalndex].isVisible
95
// m_layers[logicalndex].isVisible = !m_layers[logicalndex].isVisible;
97
m_layers[layerIndex].isVisible = visibility;
98
updateSection(layerIndex);
101
void TupExposureHeader::showEditorName(int section)
104
QFont font("Arial", 8, QFont::Normal, false);
105
m_editor->setFont(font);
107
int x = sectionViewportPosition(section);
108
m_editor->setGeometry(x, 0, sectionSize(section), height());
109
m_sectionEdited = section;
110
m_editor->setText(m_layers[section].title);
112
m_editor->setFocus();
116
void TupExposureHeader::hideEditorName()
120
if (m_sectionEdited != -1 && m_editor->isModified())
121
emit changedName(m_sectionEdited, m_editor->text());
123
m_sectionEdited = -1;
126
void TupExposureHeader::insertLayer(int layerIndex, const QString &text)
131
layer.isVisible = true;
132
layer.isLocked = false;
133
m_layers.insert(layerIndex, layer);
136
void TupExposureHeader::setLayerName(int layerIndex, const QString &text)
138
m_layers[layerIndex].title = text;
139
updateSection(layerIndex);
142
bool TupExposureHeader::signalMovedBlocked()
144
return m_blockSectionMoved;
147
void TupExposureHeader::setLockLayer(int logicalndex, bool lock)
149
m_layers[logicalndex].isLocked = lock;
150
updateSection(logicalndex);
153
void TupExposureHeader::moveLayer(int position, int newPosition)
155
m_blockSectionMoved = true;
156
moveSection(position, newPosition);
157
m_blockSectionMoved = false;
160
int TupExposureHeader::lastFrame(int layerIndex)
162
return m_layers[layerIndex].lastFrame;
165
void TupExposureHeader::removeLayer(int layerIndex)
167
m_layers.remove(layerIndex);
170
void TupExposureHeader::setLastFrame(int layerIndex, int num)
172
m_layers[layerIndex].lastFrame = num;
175
void TupExposureHeader::mousePressEvent(QMouseEvent * event)
177
int section = logicalIndexAt(event->pos());
178
int x = sectionViewportPosition(section) + 3;
180
QRect rect(x+3, 3, height()-3, height()-3);
181
if (rect.contains(event->pos())) {
182
emitVisibilityChanged(section);
184
if (currentCol != section)
185
emit selectionChanged(section);
186
QHeaderView::mousePressEvent(event);
190
void TupExposureHeader::paintSection(QPainter * painter, const QRect & rect, int layerIndex) const
195
QStyleOptionHeader headerOption;
196
headerOption.rect = rect;
197
headerOption.orientation = Qt::Horizontal;
198
headerOption.position = QStyleOptionHeader::Middle;
199
headerOption.text = "";
201
QStyle::State state = QStyle::State_None;
204
state |= QStyle::State_Enabled;
206
if (window()->isActiveWindow())
207
state |= QStyle::State_Active;
209
style()->drawControl(QStyle::CE_HeaderSection, &headerOption, painter);
211
QString text = m_layers[layerIndex].title;
212
QFont font("Arial", 8, QFont::Normal, false);
213
QFontMetrics fm(font);
215
QStyleOptionButton buttonOption;
217
if (m_layers[layerIndex].isVisible) {
218
buttonOption.palette.setBrush(QPalette::Button, Qt::green);
220
buttonOption.palette.setBrush(QPalette::Button, Qt::red);
221
buttonOption.state |= QStyle::State_Sunken;
222
QColor color(255, 0, 0, 40);
223
painter->fillRect(rect.normalized().adjusted(0, 1, 0, -1), color);
226
if ((layerIndex == currentCol) || (m_layers.size() == 1)) {
227
QColor color(250, 209, 132, 80);
228
painter->fillRect(rect.normalized().adjusted(0, 1, 0, -1), color);
229
if (m_layers[layerIndex].isVisible) {
230
painter->setPen(QPen(QColor(250, 209, 132, 255), 2, Qt::SolidLine)); // Header selected
231
painter->drawRect(rect.normalized().adjusted(0, 1, 0, -1));
233
painter->setPen(QPen(QColor(255, 0, 0, 70), 2, Qt::SolidLine)); // Header locked
234
painter->drawRect(rect.normalized().adjusted(0, 1, 0, -1));
238
int buttonWidth = 12;
239
int width = (rect.normalized().width() - (fm.width(text) + buttonWidth) + 4)/ 2;
240
int x = rect.normalized().x() + width + buttonWidth;
241
int y = rect.normalized().bottomLeft().y() - (1 + (rect.normalized().height() - fm.height())/2);
243
painter->setFont(font);
244
painter->setPen(QPen(Qt::black, 1, Qt::SolidLine));
245
painter->drawText(x, y, text);
247
buttonOption.rect = QRect(rect.x() + width - 4, rect.y() + ((rect.normalized().height()-buttonWidth)/2) + 1, buttonWidth, buttonWidth);
249
style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
252
void TupExposureHeader::updateSelection(int col)
258
int TupExposureHeader::layersTotal()
260
return m_layers.size();
263
//#include "tupexposuretable.moc"