servatrice/cockatrice/src/gameview.cpp
ebbit1q 06081bd940 add keybinds to mill cards (#3439)
* add keybinds to mill cards

Add functions to move single card from top of deck to the graveyard and
exile.
Add keybinds to move single or multiple cards from top of deck to exile
or graveyard.
Add new keybinds to settings menu.
Move settings menu items around for a better fit.
Rename a few of the items in the settings menu.
Add default keybinds: ctrl alt d/e for single/multiple cards from top of
deck to the graveyard. No defaults are set for moving to exile.

* fix shortcut menu

* fix missing tag

* rename mismatched functions

* fixed your typos

* refactor shortcutsettings

correct a lot of typos
optimize a lot of functions
this could merit a pr on its own

* set mill keybinds

* refactor add related card actions

I found a function that was completely unintelligible so I made it
remotely legible and removed the duplication.

* shorten line by 17 characters

replace a lot of function calls with just a single reference

* add brackets

add brackets to all single line if statements etc.
readability improvements
2018-11-23 22:21:20 -05:00

67 lines
2.2 KiB
C++

#include "gameview.h"
#include "gamescene.h"
#include "settingscache.h"
#include <QAction>
#include <QResizeEvent>
#include <QRubberBand>
GameView::GameView(QGraphicsScene *scene, QWidget *parent) : QGraphicsView(scene, parent), rubberBand(0)
{
setBackgroundBrush(QBrush(QColor(0, 0, 0)));
setRenderHints(QPainter::TextAntialiasing | QPainter::Antialiasing);
setFocusPolicy(Qt::NoFocus);
setViewportUpdateMode(BoundingRectViewportUpdate);
connect(scene, SIGNAL(sceneRectChanged(const QRectF &)), this, SLOT(updateSceneRect(const QRectF &)));
connect(scene, SIGNAL(sigStartRubberBand(const QPointF &)), this, SLOT(startRubberBand(const QPointF &)));
connect(scene, SIGNAL(sigResizeRubberBand(const QPointF &)), this, SLOT(resizeRubberBand(const QPointF &)));
connect(scene, SIGNAL(sigStopRubberBand()), this, SLOT(stopRubberBand()));
aCloseMostRecentZoneView = new QAction(this);
connect(aCloseMostRecentZoneView, SIGNAL(triggered()), scene, SLOT(closeMostRecentZoneView()));
addAction(aCloseMostRecentZoneView);
connect(&settingsCache->shortcuts(), SIGNAL(shortCutChanged()), this, SLOT(refreshShortcuts()));
refreshShortcuts();
rubberBand = new QRubberBand(QRubberBand::Rectangle, this);
}
void GameView::resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
GameScene *s = dynamic_cast<GameScene *>(scene());
if (s)
s->processViewSizeChange(event->size());
updateSceneRect(scene()->sceneRect());
}
void GameView::updateSceneRect(const QRectF &rect)
{
fitInView(rect, Qt::KeepAspectRatio);
}
void GameView::startRubberBand(const QPointF &_selectionOrigin)
{
selectionOrigin = _selectionOrigin;
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), QSize(0, 0)));
rubberBand->show();
}
void GameView::resizeRubberBand(const QPointF &cursorPoint)
{
if (rubberBand)
rubberBand->setGeometry(QRect(mapFromScene(selectionOrigin), cursorPoint.toPoint()).normalized());
}
void GameView::stopRubberBand()
{
rubberBand->hide();
}
void GameView::refreshShortcuts()
{
aCloseMostRecentZoneView->setShortcuts(settingsCache->shortcuts().getShortcut("Player/aCloseMostRecentZoneView"));
}