Commit cb6d38ca authored by Kevin Price's avatar Kevin Price Committed by Albert Astals Cid

Added an option under the settings menu to enable a cursor under the mouse

BUGS: 363660

Contains some tweaks by Albert Astals Cid (whitespaces et al)
parent c1ad66a8
......@@ -135,6 +135,8 @@ void KBBGraphicsItemBall::hoverEnterEvent (QGraphicsSceneHoverEvent*)
connect(m_timer, &QTimer::timeout, this, &KBBGraphicsItemBall::showInteractions);
m_timer->start(TIME_TO_WAIT_BEFORE_SHOWING_INTERACTIONS);
}
m_widget->hoverMovePosition(position());
}
......
......@@ -48,7 +48,7 @@
// Constructor / Destructor
//
KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager) : QGraphicsRectItem (0)
KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager, bool isPreview) : QGraphicsRectItem (0)
{
scene->addItem(this);
m_columns = 1;
......@@ -64,6 +64,9 @@ KBBGraphicsItemBlackBox::KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphic
m_penLines.setColor(themeManager->color(g));
m_penLines.setStyle(themeManager->style(g));
m_penLines.setWidthF(themeManager->width(g));
//accept hover events unless the central widget is a preview (crashes the program)
if (!isPreview)
setAcceptHoverEvents(true);
}
......@@ -131,3 +134,15 @@ void KBBGraphicsItemBlackBox::mousePressEvent (QGraphicsSceneMouseEvent* event)
if (m_widget!=0)
m_widget->mouseBoxClick(event->button(), x + y*m_columns);
}
void KBBGraphicsItemBlackBox::hoverLeaveEvent(QGraphicsSceneHoverEvent*)
{
m_widget->cursorOff();
}
void KBBGraphicsItemBlackBox::hoverMoveEvent(QGraphicsSceneHoverEvent* event)
{
int x = (int)(event->pos().x() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
int y = (int)(event->pos().y() - KBBScalableGraphicWidget::BORDER_SIZE)/KBBScalableGraphicWidget::RATIO;
emit hoverMoved(x + y*m_columns);
}
......@@ -43,19 +43,20 @@ class QGraphicsView;
class KBBGraphicsItem;
#include "kbbscalablegraphicwidget.h"
#include <QObject>
/**
* @brief The black box in the scalable graphic widget
*/
class KBBGraphicsItemBlackBox : public QGraphicsRectItem
class KBBGraphicsItemBlackBox : public QObject, public QGraphicsRectItem
{
Q_OBJECT
public:
/**
* @brief Constructor
*/
KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager);
KBBGraphicsItemBlackBox(QGraphicsView* parent, QGraphicsScene* scene, KBBThemeManager* themeManager, bool isPreview);
/**
......@@ -73,7 +74,9 @@ class KBBGraphicsItemBlackBox : public QGraphicsRectItem
private:
void mousePressEvent (QGraphicsSceneMouseEvent* event) Q_DECL_OVERRIDE;
void hoverMoveEvent (QGraphicsSceneHoverEvent* event) Q_DECL_OVERRIDE;
void hoverLeaveEvent (QGraphicsSceneHoverEvent* event) Q_DECL_OVERRIDE;
KBBGraphicsItem* m_background;
int m_columns;
QList<QGraphicsLineItem*> m_lines;
......@@ -82,6 +85,10 @@ class KBBGraphicsItemBlackBox : public QGraphicsRectItem
QGraphicsScene* m_scene;
KBBScalableGraphicWidget* m_widget;
int m_zValueLines;
public:
signals:
void hoverMoved(int);
void hoverExit();
};
#endif // KBBGRAPHICSITEMBLACKBOX_H
......@@ -67,14 +67,13 @@ class KBBGraphicsItemCursor : public KBBGraphicsItem
void setBoardSize(const int columns, const int rows);
void setBorderPosition(const int borderPosition);
void setBoxPosition(const int boxPosition);
void updatePositions();
signals:
void cursorAtNewPosition(const int borderPosition);
private:
void updatePositions();
int m_boxPosition;
int m_borderPosition;
......
......@@ -31,7 +31,7 @@ KBBLevelConfigurationPreview::KBBLevelConfigurationPreview(QWidget *parent, KBBT
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setScene(new QGraphicsScene(0, 0, 2*KBBScalableGraphicWidget::BORDER_SIZE, 2*KBBScalableGraphicWidget::BORDER_SIZE, this));
m_blackbox = new KBBGraphicsItemBlackBox(this, scene(), themeManager);
m_blackbox = new KBBGraphicsItemBlackBox(this, scene(), themeManager, true);
m_themeManager = themeManager;
}
......
......@@ -124,7 +124,10 @@ KBBMainWindow::KBBMainWindow()
// Menu "Settings"
KStandardAction::preferences(this, SLOT(settingsDialog()), actionCollection());
QAction* cursor = actionCollection()->addAction( QLatin1String( "toggle_cursor" ));
cursor->setText(i18n("Enable cursor under mouse"));
cursor->setCheckable(true);
connect(cursor, &QAction::triggered, this, &KBBMainWindow::toggleCursor);
// Theme manager
QString svgzFile = KBBPrefs::theme();
......@@ -473,6 +476,10 @@ void KBBMainWindow::startTutorial()
}
}
void KBBMainWindow::toggleCursor()
{
m_gameWidget->toggleCursor();
}
//
......
......@@ -72,7 +72,6 @@ class KBBMainWindow : public KXmlGuiWindow
*/
void updateStats();
private slots:
/**
* @brief Ends the current game
......@@ -125,6 +124,7 @@ class KBBMainWindow : public KXmlGuiWindow
*/
void startTutorial();
void toggleCursor();
private:
/**
......
......@@ -73,7 +73,7 @@ KBBScalableGraphicWidget::KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBTheme
m_pause = false;
m_ballNumber = 0;
m_doneAction = done;
m_cursorFollowsMouse = false;
setFrameStyle(QFrame::NoFrame);
setCacheMode(QGraphicsView::CacheBackground);
......@@ -82,7 +82,7 @@ KBBScalableGraphicWidget::KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBTheme
m_scene = new QGraphicsScene( 0, 0, 2*BORDER_SIZE, 2*BORDER_SIZE, this );
m_blackbox = new KBBGraphicsItemBlackBox(this, m_scene, m_themeManager);
m_blackbox = new KBBGraphicsItemBlackBox(this, m_scene, m_themeManager, false);
m_blackbox->setKBBScalableGraphicWidget(this);
m_balls = new KBBGraphicsItemSet(m_scene);
m_cursor = new KBBGraphicsItemCursor(this, m_themeManager);
......@@ -123,6 +123,7 @@ KBBScalableGraphicWidget::KBBScalableGraphicWidget(KBBGameDoc* gameDoc, KBBTheme
// TODO: not displayed... :(
setWhatsThis(i18n("<qt><p>This is the <b>main game area</b>.</p><ul><li>The <b>black box</b> is in the center.</li><li>On the left, there are the <b>balls</b> you have to place over the black box.</li><li>Around the black box, there are <b>lasers</b> that are replaced with <b>interaction information</b> if you use them.</li></ul></qt>"));
connect(m_blackbox, &KBBGraphicsItemBlackBox::hoverMoved, this, &KBBScalableGraphicWidget::hoverMovePosition);
}
......@@ -600,5 +601,25 @@ void KBBScalableGraphicWidget::useLaser(const int incomingPosition)
}
}
void KBBScalableGraphicWidget::hoverMovePosition(int pos)
{
if (m_cursorFollowsMouse)
{
m_cursor->show();
m_cursor->setBoxPosition(pos);
m_cursor->updatePositions();
}
}
void KBBScalableGraphicWidget::toggleCursor()
{
m_cursorFollowsMouse = !m_cursorFollowsMouse;
if (m_cursorFollowsMouse == false){
m_cursor->hide();
}
}
void KBBScalableGraphicWidget::cursorOff() {
m_cursor->hide();
}
......@@ -162,8 +162,11 @@ class KBBScalableGraphicWidget : public QGraphicsView
*/
void solve(const bool continueGame);
void toggleCursor();
public slots:
void cursorOff();
void hoverMovePosition(int newPosition);
void cursorAtNewPosition(int borderPosition);
void keyboardEnter();
void keyboardMoveDown();
......@@ -236,6 +239,7 @@ class KBBScalableGraphicWidget : public QGraphicsView
QGraphicsScene* m_scene; //TODO: Remove it because scene() already gives it back.
QLCDNumber* m_score;
KBBThemeManager* m_themeManager;
bool m_cursorFollowsMouse; //enable cursor following
};
#endif // KBBSCALABLEGRAPHICWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<gui name="kblackbox"
version="14"
version="15"
xmlns="http://www.kde.org/standards/kxmlgui/1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.kde.org/standards/kxmlgui/1.0
......@@ -13,6 +13,9 @@
<Menu name="move">
<Action name="move_done" />
</Menu>
<Menu name="settings">
<Action name="toggle_cursor" />
</Menu>
</MenuBar>
<ToolBar name="mainToolBar">
<Action name="game_new" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment