~ubuntu-branches/ubuntu/wily/tupi/wily-proposed

« back to all changes in this revision

Viewing changes to src/components/exposure/tupexposureheader.cpp

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2013-05-13 09:53:35 UTC
  • mfrom: (8.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20130513095335-3iqdvt9ne07ia25v
Tags: 0.2+git01-1
* Upload to unstable.
* Removed unnecessary versioned Build-Depends.
* Removed obsolete "DM-Upload-Allowed".
* Added Vcs links to collab-maint.
* Standards updated to version 3.9.4.
* Corrected "libavutil51"-->"libavutil-dev" in Build-Depends.
* Updated debian/watch (corrected URL, removed comments).
* Updated get-orig-source (can work from any directory).
* Updated my email address; bumped copyright years.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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>                *
 
6
 *                                                                         *
 
7
 *   Developers:                                                           *
 
8
 *   2010:                                                                 *
 
9
 *    Gustavo Gonzalez / xtingray                                          *
 
10
 *                                                                         *
 
11
 *   KTooN's versions:                                                     * 
 
12
 *                                                                         *
 
13
 *   2006:                                                                 *
 
14
 *    David Cuadrado                                                       *
 
15
 *    Jorge Cuadrado                                                       *
 
16
 *   2003:                                                                 *
 
17
 *    Fernado Roldan                                                       *
 
18
 *    Simena Dinas                                                         *
 
19
 *                                                                         *
 
20
 *   Copyright (C) 2010 Gustav Gonzalez - http://www.maefloresta.com       *
 
21
 *   License:                                                              *
 
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.                                   *
 
26
 *                                                                         *
 
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.                          *
 
31
 *                                                                         *
 
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
 ***************************************************************************/
 
35
 
 
36
#include "tupexposureheader.h"
 
37
 
 
38
#include <QHeaderView>
 
39
#include <QPainter>
 
40
#include <QStyleOptionButton>
 
41
#include <QMap>
 
42
#include <QVector>
 
43
#include <QItemDelegate>
 
44
#include <QLineEdit>
 
45
#include <QMouseEvent>
 
46
#include <QMenu>
 
47
 
 
48
#include "tdebug.h"
 
49
#include <tupglobal.h>
 
50
 
 
51
/*
 
52
struct LayerItem
 
53
{
 
54
    QString title;
 
55
    int lastFrame;
 
56
    bool isVisible;
 
57
    bool isLocked;
 
58
};
 
59
*/
 
60
 
 
61
/**
 
62
 * @author Jorge Cuadrado
 
63
 */
 
64
 
 
65
TupExposureHeader::TupExposureHeader(QWidget * parent) : QHeaderView(Qt::Horizontal, parent), m_sectionEdited(-1),
 
66
                                                       m_blockSectionMoved(false)
 
67
{
 
68
    setClickable(true);
 
69
 
 
70
    //SQA: Disabled while layers movability is enhanced 
 
71
    //setMovable(true);
 
72
 
 
73
    connect(this, SIGNAL(sectionDoubleClicked(int)), this, SLOT(showEditorName(int)));
 
74
 
 
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()));
 
79
    m_editor->hide();
 
80
}
 
81
 
 
82
TupExposureHeader::~TupExposureHeader()
 
83
{
 
84
}
 
85
 
 
86
void TupExposureHeader::emitVisibilityChanged(int section)
 
87
{
 
88
   emit visibilityChanged(visualIndex(section), !m_layers[section].isVisible);
 
89
}
 
90
 
 
91
void TupExposureHeader::setVisibilityChanged(int layerIndex, bool visibility)
 
92
{
 
93
    // Q_UNUSED(visibility);
 
94
    // FIXME: in tupexpousertable.cpp visibility or !m_layers[logicalndex].isVisible
 
95
    // m_layers[logicalndex].isVisible = !m_layers[logicalndex].isVisible;
 
96
 
 
97
    m_layers[layerIndex].isVisible = visibility;
 
98
    updateSection(layerIndex);
 
99
}
 
100
 
 
101
void TupExposureHeader::showEditorName(int section)
 
102
{
 
103
    if (section >= 0) {
 
104
        QFont font("Arial", 8, QFont::Normal, false);
 
105
        m_editor->setFont(font);
 
106
 
 
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);
 
111
        m_editor->show();
 
112
        m_editor->setFocus();
 
113
    }
 
114
}
 
115
 
 
116
void TupExposureHeader::hideEditorName()
 
117
{
 
118
    m_editor->hide();
 
119
 
 
120
    if (m_sectionEdited != -1 && m_editor->isModified())
 
121
        emit changedName(m_sectionEdited, m_editor->text());
 
122
 
 
123
    m_sectionEdited = -1;
 
124
}
 
125
 
 
126
void TupExposureHeader::insertLayer(int layerIndex, const QString &text)
 
127
{
 
128
    LayerItem layer;
 
129
    layer.title = text;
 
130
    layer.lastFrame = 0;
 
131
    layer.isVisible = true;
 
132
    layer.isLocked = false;
 
133
    m_layers.insert(layerIndex, layer);
 
134
}
 
135
 
 
136
void TupExposureHeader::setLayerName(int layerIndex, const QString &text)
 
137
{
 
138
    m_layers[layerIndex].title = text;
 
139
    updateSection(layerIndex);
 
140
}
 
141
 
 
142
bool TupExposureHeader::signalMovedBlocked()
 
143
{
 
144
    return m_blockSectionMoved;
 
145
}
 
146
 
 
147
void TupExposureHeader::setLockLayer(int logicalndex, bool lock)
 
148
{
 
149
    m_layers[logicalndex].isLocked = lock;
 
150
    updateSection(logicalndex);
 
151
}
 
152
 
 
153
void TupExposureHeader::moveLayer(int position, int newPosition)
 
154
{
 
155
    m_blockSectionMoved = true;
 
156
    moveSection(position, newPosition);
 
157
    m_blockSectionMoved = false;
 
158
}
 
159
 
 
160
int TupExposureHeader::lastFrame(int layerIndex)
 
161
{
 
162
    return m_layers[layerIndex].lastFrame;
 
163
}
 
164
 
 
165
void TupExposureHeader::removeLayer(int layerIndex)
 
166
{
 
167
    m_layers.remove(layerIndex);
 
168
}
 
169
 
 
170
void TupExposureHeader::setLastFrame(int layerIndex, int num)
 
171
{
 
172
    m_layers[layerIndex].lastFrame = num;
 
173
}
 
174
 
 
175
void TupExposureHeader::mousePressEvent(QMouseEvent * event)
 
176
{
 
177
    int section = logicalIndexAt(event->pos());
 
178
    int x = sectionViewportPosition(section) + 3;
 
179
 
 
180
    QRect rect(x+3, 3, height()-3, height()-3);
 
181
    if (rect.contains(event->pos())) {
 
182
        emitVisibilityChanged(section);
 
183
    } else {
 
184
        if (currentCol != section)
 
185
            emit selectionChanged(section);
 
186
        QHeaderView::mousePressEvent(event);
 
187
    }
 
188
}
 
189
 
 
190
void TupExposureHeader::paintSection(QPainter * painter, const QRect & rect, int layerIndex) const
 
191
{
 
192
    if (!rect.isValid()) 
 
193
        return;
 
194
 
 
195
    QStyleOptionHeader headerOption;
 
196
    headerOption.rect = rect;
 
197
    headerOption.orientation = Qt::Horizontal;
 
198
    headerOption.position = QStyleOptionHeader::Middle;
 
199
    headerOption.text = "";
 
200
 
 
201
    QStyle::State state = QStyle::State_None;
 
202
 
 
203
    if (isEnabled())
 
204
        state |= QStyle::State_Enabled;
 
205
 
 
206
    if (window()->isActiveWindow())
 
207
        state |= QStyle::State_Active;
 
208
 
 
209
    style()->drawControl(QStyle::CE_HeaderSection, &headerOption, painter);
 
210
 
 
211
    QString text = m_layers[layerIndex].title;
 
212
    QFont font("Arial", 8, QFont::Normal, false);
 
213
    QFontMetrics fm(font);
 
214
 
 
215
    QStyleOptionButton buttonOption;
 
216
 
 
217
    if (m_layers[layerIndex].isVisible) {
 
218
        buttonOption.palette.setBrush(QPalette::Button, Qt::green);
 
219
    } else {
 
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);
 
224
    }
 
225
 
 
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));
 
232
        } else { 
 
233
            painter->setPen(QPen(QColor(255, 0, 0, 70), 2, Qt::SolidLine)); // Header locked
 
234
            painter->drawRect(rect.normalized().adjusted(0, 1, 0, -1));
 
235
        }
 
236
    }
 
237
 
 
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);
 
242
 
 
243
    painter->setFont(font);
 
244
    painter->setPen(QPen(Qt::black, 1, Qt::SolidLine));
 
245
    painter->drawText(x, y, text);
 
246
 
 
247
    buttonOption.rect = QRect(rect.x() + width - 4, rect.y() + ((rect.normalized().height()-buttonWidth)/2) + 1, buttonWidth, buttonWidth);
 
248
  
 
249
    style()->drawControl(QStyle::CE_PushButton, &buttonOption, painter);
 
250
}
 
251
 
 
252
void TupExposureHeader::updateSelection(int col)
 
253
{
 
254
    currentCol = col;
 
255
    updateSection(col);
 
256
}
 
257
 
 
258
int TupExposureHeader::layersTotal()
 
259
{
 
260
    return m_layers.size();
 
261
}
 
262
 
 
263
//#include "tupexposuretable.moc"