Merge pull request #25 from garakmon/cursors

Cursor update
This commit is contained in:
Marcus Huderle 2018-09-13 17:02:22 -05:00 committed by GitHub
commit 6d19da8d88
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 198 additions and 15 deletions

View file

@ -1484,9 +1484,15 @@ void MapPixmapItem::updateCurHoveredTile(QPointF pos) {
void MapPixmapItem::hoverMoveEvent(QGraphicsSceneHoverEvent *event) {
updateCurHoveredTile(event->pos());
if (editor->ui->actionBetter_Cursors->isChecked()){
setCursor(editor->cursor);
}
}
void MapPixmapItem::hoverLeaveEvent(QGraphicsSceneHoverEvent *event) {
map->clearHoveredTile();
if (editor->ui->actionBetter_Cursors->isChecked()){
unsetCursor();
}
}
void MapPixmapItem::mousePressEvent(QGraphicsSceneMouseEvent *event) {
QPointF pos = event->pos();

View file

@ -7,6 +7,7 @@
#include <QGraphicsItemAnimation>
#include <QComboBox>
#include <QCheckBox>
#include <QCursor>
#include "project.h"
#include "ui_mainwindow.h"
@ -108,6 +109,8 @@ public:
QList<int> *copiedMetatileSelection = new QList<int>;
QString map_edit_mode;
QString prev_edit_mode;
QCursor cursor;
void objectsView_onMousePress(QMouseEvent *event);
void objectsView_onMouseMove(QMouseEvent *event);

View file

@ -18,6 +18,8 @@
#include <QPushButton>
#include <QMessageBox>
#include <QDialogButtonBox>
#include <QScroller>
#include <math.h>
#include <QProcess>
#include <QSysInfo>
#include <QDesktopServices>
@ -35,6 +37,7 @@ MainWindow::MainWindow(QWidget *parent) :
connect(ui->newEventToolButton, SIGNAL(newEventAdded(QString)), this, SLOT(addNewEvent(QString)));
new QShortcut(QKeySequence(Qt::CTRL + Qt::SHIFT + Qt::Key_Z), this, SLOT(redo()));
new QShortcut(Qt::Key_M, this, SLOT(toggleEditModeMove()));
editor = new Editor(ui);
connect(editor, SIGNAL(objectsChanged()), this, SLOT(updateSelectedObjects()));
@ -55,6 +58,10 @@ MainWindow::MainWindow(QWidget *parent) :
openProject(default_dir);
}
}
if (settings.contains("cursor_mode") && settings.value("cursor_mode") == "0") {
ui->actionBetter_Cursors->setChecked(false);
}
}
MainWindow::~MainWindow()
@ -599,6 +606,36 @@ void MainWindow::on_actionRedo_triggered()
redo();
}
void MainWindow::on_actionZoom_In_triggered() {
scaleMapView(1);
}
void MainWindow::on_actionZoom_Out_triggered() {
scaleMapView(-1);
}
void MainWindow::on_actionBetter_Cursors_triggered() {
QSettings settings;
settings.setValue("cursor_mode", QString::number(ui->actionBetter_Cursors->isChecked()));
}
void MainWindow::scaleMapView(int s) {
editor->map->scale_exp += s;
double base = (double)editor->map->scale_base;
double exp = editor->map->scale_exp;
double sfactor = pow(base,s);
ui->graphicsView_Map->scale(sfactor,sfactor);
ui->graphicsView_Objects_Map->scale(sfactor,sfactor);
ui->graphicsView_Map->setFixedSize((editor->scene->width() + 2) * pow(base,exp),
(editor->scene->height() + 2) * pow(base,exp));
ui->graphicsView_Objects_Map->setFixedSize((editor->scene->width() + 2) * pow(base,exp),
(editor->scene->height() + 2) * pow(base,exp));
}
void MainWindow::addNewEvent(QString event_type)
{
if (editor) {
@ -899,24 +936,60 @@ void MainWindow::on_toolButton_Open_Scripts_clicked()
void MainWindow::on_toolButton_Paint_clicked()
{
editor->map_edit_mode = "paint";
editor->cursor = QCursor(QPixmap(":/icons/pencil_cursor.ico"), 10, 10);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QScroller::ungrabGesture(ui->scrollArea);
checkToolButtons();
}
void MainWindow::on_toolButton_Select_clicked()
{
editor->map_edit_mode = "select";
editor->cursor = QCursor(QPixmap(":/icons/cursor.ico"), 0, 0);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QScroller::ungrabGesture(ui->scrollArea);
checkToolButtons();
}
void MainWindow::on_toolButton_Fill_clicked()
{
editor->map_edit_mode = "fill";
editor->cursor = QCursor(QPixmap(":/icons/fill_color_cursor.ico"), 10, 10);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QScroller::ungrabGesture(ui->scrollArea);
checkToolButtons();
}
void MainWindow::on_toolButton_Dropper_clicked()
{
editor->map_edit_mode = "pick";
editor->cursor = QCursor(QPixmap(":/icons/pipette_cursor.ico"), 10, 10);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
QScroller::ungrabGesture(ui->scrollArea);
checkToolButtons();
}
void MainWindow::on_toolButton_Move_clicked()
{
editor->map_edit_mode = "move";
editor->cursor = QCursor(QPixmap(":/icons/move.ico"), 7, 7);
ui->scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
ui->scrollArea->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
QScroller::grabGesture(ui->scrollArea, QScroller::LeftMouseButtonGesture);
checkToolButtons();
}
@ -925,6 +998,25 @@ void MainWindow::checkToolButtons() {
ui->toolButton_Select->setChecked(editor->map_edit_mode == "select");
ui->toolButton_Fill->setChecked(editor->map_edit_mode == "fill");
ui->toolButton_Dropper->setChecked(editor->map_edit_mode == "pick");
ui->toolButton_Move->setChecked(editor->map_edit_mode == "move");
}
void MainWindow::toggleEditModeMove() {
if (editor->map_edit_mode == "move") {
if (editor->prev_edit_mode == "paint") {
on_toolButton_Paint_clicked();
} else if (editor->prev_edit_mode == "fill") {
on_toolButton_Fill_clicked();
} else if (editor->prev_edit_mode == "pick") {
on_toolButton_Dropper_clicked();
} else if (editor->prev_edit_mode == "select") {
on_toolButton_Select_clicked();
}
}
else {
editor->prev_edit_mode = editor->map_edit_mode;
on_toolButton_Move_clicked();
}
}
void MainWindow::onLoadMapRequested(QString mapName, QString fromMapName) {

View file

@ -37,6 +37,7 @@ private slots:
void undo();
void redo();
void toggleEditModeMove();
void openInTextEditor();
void onLoadMapRequested(QString, QString);
@ -60,6 +61,10 @@ private slots:
void on_actionRedo_triggered();
void on_actionZoom_In_triggered();
void on_actionZoom_Out_triggered();
void on_actionBetter_Cursors_triggered();
void on_toolButton_deleteObject_clicked();
void on_toolButton_Open_Scripts_clicked();
@ -74,6 +79,8 @@ private slots:
void on_toolButton_Dropper_clicked();
void on_toolButton_Move_clicked();
void onOpenMapListContextMenu(const QPoint &point);
void onAddNewMapToGroupClick(QAction* triggeredAction);
void onTilesetChanged(QString);
@ -127,6 +134,8 @@ private:
void displayMapProperties();
void checkToolButtons();
void scaleMapView(int);
};
enum MapListUserRoles {

View file

@ -245,6 +245,23 @@
</property>
</widget>
</item>
<item>
<widget class="QToolButton" name="toolButton_Move">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Move&lt;/p&gt;&lt;p&gt;Click to drag map around.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>...</string>
</property>
<property name="icon">
<iconset resource="resources/images.qrc">
<normaloff>:/icons/move.ico</normaloff>:/icons/move.ico</iconset>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBox_smartPaths">
<property name="toolTip">
@ -334,8 +351,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>462</width>
<height>599</height>
<width>429</width>
<height>620</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_8">
@ -362,9 +379,18 @@
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="mouseTracking">
<bool>false</bool>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustIgnored</enum>
</property>
<property name="dragMode">
<enum>QGraphicsView::NoDrag</enum>
</property>
</widget>
</item>
<item row="1" column="0">
@ -708,7 +734,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<width>315</width>
<height>86</height>
</rect>
</property>
@ -812,10 +838,10 @@
</property>
<property name="geometry">
<rect>
<x>8</x>
<x>0</x>
<y>0</y>
<width>323</width>
<height>368</height>
<width>365</width>
<height>405</height>
</rect>
</property>
<property name="sizePolicy">
@ -1050,8 +1076,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>371</width>
<height>643</height>
<width>381</width>
<height>657</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_7">
@ -1216,8 +1242,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>410</width>
<height>560</height>
<width>420</width>
<height>584</height>
</rect>
</property>
<property name="sizePolicy">
@ -1872,8 +1898,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>818</width>
<height>539</height>
<width>826</width>
<height>557</height>
</rect>
</property>
<layout class="QGridLayout" name="gridLayout_14">
@ -2045,7 +2071,7 @@
<x>0</x>
<y>0</y>
<width>1117</width>
<height>22</height>
<height>21</height>
</rect>
</property>
<widget class="QMenu" name="menuFile">
@ -2067,8 +2093,17 @@
<addaction name="actionUndo"/>
<addaction name="actionRedo"/>
</widget>
<widget class="QMenu" name="menuView">
<property name="title">
<string>View</string>
</property>
<addaction name="actionZoom_In"/>
<addaction name="actionZoom_Out"/>
<addaction name="actionBetter_Cursors"/>
</widget>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuView"/>
</widget>
<widget class="QStatusBar" name="statusBar"/>
<action name="action_Save_Project">
@ -2127,6 +2162,36 @@
<string>Export Map Image...</string>
</property>
</action>
<action name="actionZoom_In">
<property name="text">
<string>Zoom In</string>
</property>
<property name="shortcut">
<string>+</string>
</property>
</action>
<action name="actionZoom_Out">
<property name="text">
<string>Zoom Out</string>
</property>
<property name="shortcut">
<string>-</string>
</property>
</action>
<action name="actionBetter_Cursors">
<property name="checkable">
<bool>true</bool>
</property>
<property name="checked">
<bool>true</bool>
</property>
<property name="text">
<string>Cursor Icons</string>
</property>
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Use reticule-styled cursors with icon showing currently selected tool.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
</action>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>

View file

@ -608,10 +608,11 @@ bool Map::hasUnsavedChanges() {
}
void Map::hoveredTileChanged(int x, int y, int block) {
emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3")
emit statusBarMessage(QString("X: %1, Y: %2, Metatile: 0x%3, Scale = %4x")
.arg(x)
.arg(y)
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper()));
.arg(QString("%1").arg(block, 3, 16, QChar('0')).toUpper())
.arg(QString::number(pow(this->scale_base,this->scale_exp))));
}
void Map::clearHoveredTile() {

3
map.h
View file

@ -9,6 +9,7 @@
#include <QObject>
#include <QDebug>
#include <QGraphicsPixmapItem>
#include <math.h>
class HistoryItem {
public:
@ -135,6 +136,8 @@ public:
QString show_location;
QString battle_scene;
MapLayout *layout;
int scale_exp = 0;
double scale_base = sqrt(2); // adjust scale factor with this
bool isPersistedToFile = true;

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

BIN
resources/icons/move.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View file

@ -9,6 +9,7 @@
<file>icons/map.ico</file>
<file>icons/cursor.ico</file>
<file>icons/fill_color.ico</file>
<file>icons/move.ico</file>
<file>icons/pencil.ico</file>
<file>icons/pipette.ico</file>
<file>images/Entities_16x16.png</file>
@ -16,5 +17,8 @@
<file>icons/delete.ico</file>
<file>icons/viewsprites.ico</file>
<file>images/collisions.png</file>
<file>icons/fill_color_cursor.ico</file>
<file>icons/pencil_cursor.ico</file>
<file>icons/pipette_cursor.ico</file>
</qresource>
</RCC>