15
by myst6re
BUG fix: reload does not work for memcard files. |
1 |
/****************************************************************************
|
2 |
** Hyne Final Fantasy VIII Save Editor
|
|
124
by myst6re
Merging Qt5 branch in trunk: |
3 |
** Copyright (C) 2009-2013 Arzel Jérôme <myst6re@gmail.com>
|
15
by myst6re
BUG fix: reload does not work for memcard files. |
4 |
**
|
5 |
** This program is free software: you can redistribute it and/or modify
|
|
6 |
** it under the terms of the GNU General Public License as published by
|
|
7 |
** the Free Software Foundation, either version 3 of the License, or
|
|
8 |
** (at your option) any later version.
|
|
9 |
**
|
|
10 |
** This program is distributed in the hope that it will be useful,
|
|
11 |
** but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
** GNU General Public License for more details.
|
|
14 |
**
|
|
15 |
** You should have received a copy of the GNU General Public License
|
|
16 |
** along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
17 |
****************************************************************************/
|
|
2
by myst6re
First commit |
18 |
#include "StartWidget.h" |
43
by myst6re
Adding SavecardData::saveCount function for cleaner code. |
19 |
#include "SavecardView.h" |
2
by myst6re
First commit |
20 |
|
21 |
StartWidget::StartWidget(QWidget *parent) : |
|
31
by myst6re
The start widget is finished! |
22 |
QWidget(parent), _cursorPosition(-1) |
23 |
{
|
|
24 |
setMouseTracking(true); |
|
25 |
}
|
|
26 |
||
27 |
void StartWidget::addAction(QAction *action) |
|
28 |
{
|
|
29 |
QWidget::addAction(action); |
|
30 |
}
|
|
31 |
||
32 |
QAction *StartWidget::addAction(const QString &text) |
|
33 |
{
|
|
34 |
QAction *act = new QAction(text, this); |
|
35 |
addAction(act); |
|
36 |
return act; |
|
37 |
}
|
|
38 |
||
39 |
QAction *StartWidget::addAction(const QString &text, const QObject *receiver, const char *method) |
|
40 |
{
|
|
41 |
QAction *act = addAction(text); |
|
42 |
connect(act, SIGNAL(triggered()), receiver, method); |
|
43 |
return act; |
|
44 |
}
|
|
45 |
||
46 |
void StartWidget::setCursorPosition(int actionID) |
|
47 |
{
|
|
48 |
_cursorPosition = actionID; |
|
37
by myst6re
Change the startWidget and the main window to use less of memory. Gain: ~15MB (dafuck!?) |
49 |
update(actionsPosition().x()-38, actionsPosition().y()+12, 48, 30 + actions().size() * OPTION_HEIGHT); |
31
by myst6re
The start widget is finished! |
50 |
}
|
51 |
||
52 |
int StartWidget::actionID(const QPoint &pos) const |
|
53 |
{
|
|
37
by myst6re
Change the startWidget and the main window to use less of memory. Gain: ~15MB (dafuck!?) |
54 |
if(pos.x() < actionsPosition().x() |
55 |
|| pos.x() >= actionsPosition().x() + sizeHint().width() |
|
56 |
|| pos.y() < actionsPosition().y() |
|
57 |
|| pos.y() >= actionsPosition().y() + sizeHint().height()) |
|
58 |
return -1; |
|
31
by myst6re
The start widget is finished! |
59 |
|
37
by myst6re
Change the startWidget and the main window to use less of memory. Gain: ~15MB (dafuck!?) |
60 |
return (pos.y() - actionsPosition().y()) / OPTION_HEIGHT; |
2
by myst6re
First commit |
61 |
}
|
62 |
||
63 |
void StartWidget::paintEvent(QPaintEvent *) |
|
64 |
{
|
|
31
by myst6re
The start widget is finished! |
65 |
if(actions().isEmpty()) return; |
66 |
||
67 |
QRegExp remAnd("&([^&])"); |
|
68 |
bool enabledState = actions().first()->isEnabled(); |
|
69 |
int actionID = 0; |
|
70 |
QPainter painter(this); |
|
71 |
||
37
by myst6re
Change the startWidget and the main window to use less of memory. Gain: ~15MB (dafuck!?) |
72 |
painter.setBrush(Qt::black); |
42
by myst6re
New list view that use a simple QScrollArea/QWidget instead of a QListWidget with widget items. |
73 |
painter.drawRect(rect()); |
37
by myst6re
Change the startWidget and the main window to use less of memory. Gain: ~15MB (dafuck!?) |
74 |
|
75 |
painter.translate(actionsPosition()); |
|
76 |
||
31
by myst6re
The start widget is finished! |
77 |
painter.setBrush(QPixmap(QString(":/images/menu-fond%1.png").arg(enabledState ? "" : "2"))); |
78 |
||
79 |
foreach(const QAction *act, actions()) { |
|
80 |
if(act->isEnabled() != enabledState) { |
|
81 |
enabledState = act->isEnabled(); |
|
82 |
painter.setBrush(QPixmap(QString(":/images/menu-fond%1.png").arg(enabledState ? "" : "2"))); |
|
83 |
}
|
|
84 |
||
85 |
QString text = act->text(); |
|
86 |
text.replace(remAnd, "\\1"); |
|
87 |
||
42
by myst6re
New list view that use a simple QScrollArea/QWidget instead of a QListWidget with widget items. |
88 |
SavecardView::drawFrame(&painter, OPTION_WIDTH, OPTION_HEIGHT); |
40
by myst6re
Reduce used memory: |
89 |
FF8Text::drawTextArea(&painter, QPoint(12, 12), text); |
31
by myst6re
The start widget is finished! |
90 |
|
91 |
if(actionID == _cursorPosition) { |
|
92 |
painter.drawPixmap(-38, 12, QPixmap(":/images/cursor.png")); |
|
93 |
}
|
|
94 |
||
95 |
painter.translate(0, OPTION_HEIGHT); |
|
96 |
++actionID; |
|
97 |
}
|
|
98 |
||
99 |
painter.end(); |
|
100 |
}
|
|
101 |
||
102 |
void StartWidget::mouseMoveEvent(QMouseEvent *event) |
|
103 |
{
|
|
104 |
int actionID = this->actionID(event->pos()); |
|
105 |
||
106 |
if(actionID >= 0 && actionID < actions().size()) { |
|
107 |
QAction *act = actions().at(actionID); |
|
108 |
if(act->isEnabled()) { |
|
109 |
act->hover(); |
|
110 |
setCursorPosition(actionID); |
|
111 |
} else { |
|
112 |
setCursorPosition(-1); |
|
113 |
}
|
|
114 |
}
|
|
115 |
}
|
|
116 |
||
117 |
void StartWidget::mouseReleaseEvent(QMouseEvent *event) |
|
118 |
{
|
|
119 |
int actionID = this->actionID(event->pos()); |
|
120 |
||
121 |
if(actionID >= 0 && actionID < actions().size()) { |
|
122 |
QAction *act = actions().at(actionID); |
|
123 |
if(act->isEnabled()) { |
|
124 |
act->trigger(); |
|
125 |
emit actionTriggered(act); |
|
126 |
}
|
|
127 |
}
|
|
128 |
}
|
|
129 |
||
130 |
void StartWidget::leaveEvent(QEvent *) |
|
131 |
{
|
|
132 |
setCursorPosition(-1); |
|
2
by myst6re
First commit |
133 |
}
|