Skip to content

Commit

Permalink
Add a tileset debugger skeleton class
Browse files Browse the repository at this point in the history
See #632.
  • Loading branch information
lmoureaux committed Sep 12, 2021
1 parent c0404d5 commit 1c589a4
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 0 deletions.
1 change: 1 addition & 0 deletions client/gui-qt/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ add_library(
spaceshipdlg.cpp
sprite.cpp
themes.cpp
tileset_debugger.cpp
tradecalculation.cpp
tooltips.cpp
unitreport.cpp
Expand Down
86 changes: 86 additions & 0 deletions client/gui-qt/tileset_debugger.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**************************************************************************
Copyright (c) 2021 Freeciv21 contributors. This file is
part of Freeciv21. Freeciv21 is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. You should have received
a copy of the GNU General Public License along with Freeciv21. If not,
see https://www.gnu.org/licenses/.
**************************************************************************/

#include "tileset_debugger.h"

// common
#include "map.h"
#include "tile.h"

// utility
#include "fcintl.h"

#include <QLabel>
#include <QToolBar>
#include <QVBoxLayout>

namespace freeciv {

/**
* \class tileset_debugger
* \brief A dialog to perform debugging of the tileset.
*/

/**
* Constructor.
*/
tileset_debugger::tileset_debugger(QWidget *parent) : QDialog(parent)
{
auto layout = new QVBoxLayout;
setLayout(layout);

auto toolbar = new QToolBar;
toolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
layout->addWidget(toolbar);

m_pick_action =
toolbar->addAction(QIcon::fromTheme("pointer"), _("Pick tile"));
m_pick_action->setToolTip(_("Pick a tile to inspect on the map"));
m_pick_action->setCheckable(true);
connect(m_pick_action, &QAction::toggled, this,
&tileset_debugger::pick_tile);

m_label = new QLabel;
layout->addWidget(m_label, 100, Qt::AlignCenter);

set_tile(nullptr);
}

/**
* Destructor.
*/
tileset_debugger::~tileset_debugger() {}

/**
* Sets the tile being debugged.
*/
void tileset_debugger::set_tile(const ::tile *t)
{
m_tile = t;

// Update the GUI
if (!t) {
m_label->setText(_("No tile selected"));
return;
}

m_label->setText(QStringLiteral("%1 %2").arg(
index_to_map_pos_x(tile_index(t)), index_to_map_pos_y(tile_index(t))));
}

/**
* Enters or exits tile picking mode.
*/
void tileset_debugger::pick_tile(bool active)
{
emit tile_picking_requested(active);
}

} // namespace freeciv
43 changes: 43 additions & 0 deletions client/gui-qt/tileset_debugger.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**************************************************************************
Copyright (c) 2021 Freeciv21 contributors. This file is
part of Freeciv21. Freeciv21 is free software: you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version. You should have received
a copy of the GNU General Public License along with Freeciv21. If not,
see https://www.gnu.org/licenses/.
**************************************************************************/
#pragma once

#include <QDialog>

class QAction;
class QLabel;

struct tile;

namespace freeciv {

class tileset_debugger : public QDialog {
Q_OBJECT

public:
explicit tileset_debugger(QWidget *parent = nullptr);
virtual ~tileset_debugger();

const ::tile *tile() const { return m_tile; }
void set_tile(const ::tile *t);

signals:
void tile_picking_requested(bool active);

private slots:
void pick_tile(bool active);

private:
const ::tile *m_tile;
QLabel *m_label;
QAction *m_pick_action;
};

} // namespace freeciv

0 comments on commit 1c589a4

Please sign in to comment.