Skip to content
Permalink
Browse files

Qt client - allowed styling titlebar of dialog.

See hrm Feature #710896
  • Loading branch information...
mir3x
mir3x committed Nov 17, 2017
1 parent 828efe7 commit f1adf62cbb15bdc6ffb12fe3f505e7be9257f9ae
@@ -1392,7 +1392,7 @@ void city_map::context_menu(QPoint point)
/****************************************************************************
Constructor for city_dialog, sets layouts, policies ...
****************************************************************************/
city_dialog::city_dialog(QWidget *parent): QDialog(parent)
city_dialog::city_dialog(QWidget *parent): qfc_dialog(parent)
{
int info_nr;
int iter;
@@ -1430,9 +1430,7 @@ city_dialog::city_dialog(QWidget *parent): QDialog(parent)
prod_unit_splitter = new QSplitter;
prod_unit_splitter->setOpaqueResize(false);

setParent(parent);
setMouseTracking(true);
setWindowFlags(Qt::Dialog);
selected_row_p = -1;
pcity = NULL;
lcity_name = new QPushButton(this);
@@ -51,6 +51,7 @@ class QVBoxLayout;

// gui-qt
#include "fonts.h"
#include "dialogs.h"

// Qt
#include <QProgressBar>
@@ -396,7 +397,7 @@ class city_label: public QLabel
/****************************************************************************
City dialog
****************************************************************************/
class city_dialog: public QDialog
class city_dialog: public qfc_dialog
{

Q_OBJECT
@@ -152,11 +152,99 @@ static const QHash<enum gen_action, pfcn_void> af_map_init(void)
* pushed. */
static const QHash<enum gen_action, pfcn_void> af_map = af_map_init();

/***************************************************************************
Constructor for custom dialog with themed titlebar
***************************************************************************/
qfc_dialog::qfc_dialog(QWidget* parent) : QDialog(parent,
Qt::FramelessWindowHint)
{
titlebar_height = 0;
moving_now = false;
setSizeGripEnabled(true);
close_pix = *fc_icons::instance()->get_pixmap("cclose");
}

/***************************************************************************
Paint event for themed dialog
***************************************************************************/
void qfc_dialog::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event)

QPainter p(this);
QStyleOptionTitleBar tbar_opt;
QStyleOption win_opt;
QStyle *style = this->style();
QRect active_area = this->rect();
QPalette qpal;
QRect close_rect, text_rect;

qpal.setColor(QPalette::Active, QPalette::ToolTipText, Qt::white);
tbar_opt.initFrom(this);
titlebar_height = style->pixelMetric(QStyle::PM_TitleBarHeight,
&tbar_opt, this) + 2;
close_pix = close_pix.scaledToHeight(titlebar_height);
tbar_opt.rect = QRect(0, 0, this->width(), titlebar_height);
text_rect = QRect(0, 0, this->width() - close_pix.width() , titlebar_height);
close_rect = QRect(this->width() - close_pix.width(), 0, this->width(),
titlebar_height);
tbar_opt.titleBarState = this->windowState();
tbar_opt.text = tbar_opt.fontMetrics.elidedText(this->windowTitle(),
Qt::ElideRight,
text_rect.width());
style->drawComplexControl(QStyle::CC_TitleBar, &tbar_opt, &p, this);
style->drawItemText(&p, text_rect, Qt::AlignCenter, qpal,
true, tbar_opt.text, QPalette::ToolTipText);
style->drawItemPixmap(&p, close_rect, Qt::AlignLeft,
close_pix.scaledToHeight(titlebar_height));

active_area.setTopLeft(QPoint(0, titlebar_height));
this->setContentsMargins(0, titlebar_height, 0, 0);
win_opt.initFrom(this);
win_opt.rect = active_area;
style->drawPrimitive(QStyle::PE_Widget, &win_opt, &p, this);
}

/***************************************************************************
Mouse move event for themed titlebar (moves dialog with left mouse)
***************************************************************************/
void qfc_dialog::mouseMoveEvent(QMouseEvent *event)
{
if (moving_now == true) {
move(event->globalPos() - point);
}
}

/***************************************************************************
Mouse press event - catches left click
***************************************************************************/
void qfc_dialog::mousePressEvent(QMouseEvent *event)
{
if (event->pos().y() <= titlebar_height
&& event->pos().x() <= width() - close_pix.width()) {
point = event->globalPos() - geometry().topLeft();
moving_now = true;
setCursor(Qt::SizeAllCursor);
} else if (event->pos().y() <= titlebar_height
&& event->pos().x() > width() - close_pix.width()) {
close();
}
}

/***************************************************************************
Mouse release event for themed dialog
***************************************************************************/
void qfc_dialog::mouseReleaseEvent(QMouseEvent *event)
{
moving_now = false;
setCursor(Qt::ArrowCursor);
}

/***************************************************************************
Constructor for selecting nations
***************************************************************************/
races_dialog::races_dialog(struct player *pplayer,
QWidget *parent) : QDialog(parent)
races_dialog::races_dialog(struct player *pplayer,
QWidget *parent) : qfc_dialog(parent)
{
int i;
QGridLayout *qgroupbox_layout;
@@ -67,6 +67,26 @@ class qdef_act
int vs_unit_get();
};

/***************************************************************************
Dialog with themed titlebar
***************************************************************************/
class qfc_dialog : public QDialog
{
Q_OBJECT
public:
qfc_dialog(QWidget *parent);
private:
int titlebar_height;
QPoint point;
bool moving_now;
QPixmap close_pix;
protected:
void paintEvent(QPaintEvent* event);
void mouseMoveEvent(QMouseEvent *event);
void mousePressEvent(QMouseEvent *event);
void mouseReleaseEvent(QMouseEvent *event);
};

/***************************************************************************
Nonmodal message box for disbanding units
***************************************************************************/
@@ -104,7 +124,7 @@ private slots:
/***************************************************************************
Dialog for selecting nation, style and leader leader
***************************************************************************/
class races_dialog:public QDialog
class races_dialog:public qfc_dialog
{
Q_OBJECT
QGridLayout *main_layout;
@@ -114,8 +114,7 @@ void update_help_fonts()
/**************************************************************************
Constructor for help dialog
**************************************************************************/
help_dialog::help_dialog(QWidget *parent) :
QDialog(parent)
help_dialog::help_dialog(QWidget *parent) : qfc_dialog(parent)
{
QHBoxLayout *hbox;
QList<int> sizes;
@@ -126,7 +125,6 @@ help_dialog::help_dialog(QWidget *parent) :
QWidget *buttons;

setWindowTitle(_("Freeciv Help Browser"));
setWindowFlags(Qt::WindowStaysOnTopHint);
resize(750, 450);
history_pos = -1;
update_history = true;
@@ -22,6 +22,9 @@
#include <QHash>
#include <QList>

// gui-qt
#include "dialogs.h"

extern "C" {
#include "helpdlg_g.h"
}
@@ -40,7 +43,7 @@ class QVBoxLayout;

class help_widget;

class help_dialog : public QDialog
class help_dialog : public qfc_dialog
{
Q_OBJECT
QPushButton *prev_butt;
@@ -126,7 +126,7 @@ QString cut_helptext(QString text)
****************************************************************************/
option_dialog::option_dialog(const QString & name,
const option_set *options, QWidget *parent)
: QDialog (parent)
: qfc_dialog(parent)
{
QPushButton *but;

@@ -18,11 +18,13 @@ extern "C" {
#include "optiondlg_g.h"
}


// Qt
#include <QDialog>
#include <QMap>

// qt-client
#include <dialogs.h>

class Qdialog;
class QVBoxLayout;
class QTabWidget;
@@ -36,7 +38,7 @@ QString cut_helptext(QString text);
/****************************************************************************
Dialog for client/server options
****************************************************************************/
class option_dialog : public QDialog
class option_dialog : public qfc_dialog
{
Q_OBJECT
QVBoxLayout * main_layout;
@@ -28,6 +28,7 @@

// gui-qt
#include "fc_client.h"
#include "dialogs.h"
#include "qtg_cxxside.h"
#include "sprite.h"

@@ -41,7 +42,7 @@ static int mult_to_scale(const struct multiplier *pmul, int val);
Automatic destructor will clean qobjects, so there is no one
**************************************************************************/
tax_rates_dialog::tax_rates_dialog(QWidget *parent)
: QDialog(parent)
: qfc_dialog(parent)
{
QHBoxLayout *some_layout;
QVBoxLayout *main_layout;
@@ -128,7 +129,7 @@ void tax_rates_dialog::slot_apply_button_pressed()
**************************************************************************/
multipler_rates_dialog::multipler_rates_dialog(QWidget *parent,
Qt::WindowFlags f)
: QDialog(parent)
: qfc_dialog(parent)
{
QGroupBox *group_box;
QHBoxLayout *some_layout;
@@ -321,7 +322,7 @@ fc_double_edge::~fc_double_edge()
QSize fc_double_edge::sizeHint() const
{
return QSize(30 * get_tax_sprite(tileset, O_LUXURY)->pm->width(),
2 * get_tax_sprite(tileset, O_LUXURY)->pm->height());
3 * get_tax_sprite(tileset, O_LUXURY)->pm->height());
}

/**************************************************************************
@@ -31,6 +31,9 @@
// client
#include "client_main.h"

// gui-qt
#include "dialogs.h"

extern "C" {
#include "ratesdlg_g.h"
}
@@ -73,7 +76,7 @@ class fc_double_edge : public QWidget
/**************************************************************************
* Dialog used to change tax rates
*************************************************************************/
class tax_rates_dialog: public QDialog
class tax_rates_dialog: public qfc_dialog
{
Q_OBJECT

@@ -91,7 +94,7 @@ private slots:
/**************************************************************************
* Dialog used to change policies
*************************************************************************/
class multipler_rates_dialog: public QDialog
class multipler_rates_dialog: public qfc_dialog
{
Q_OBJECT

@@ -26,6 +26,11 @@ QMainWindow {
border: 2px solid #c3b48e;
}

qfc_dialog::title {
font-weight: bold;
background-color: #a1936e;
}

close_widget
{
background: #ddca97;
@@ -47,6 +47,10 @@ resize_widget
background: #006633;
}

qfc_dialog::title {
font-weight: bold;
background-color: #10691a;
}

QPushButton {
color: black;
@@ -100,6 +100,10 @@ unit_hud_selector, tax_rates_dialog QPushButton {
min-width: 160px;
}

qfc_dialog::title {
font-weight: bold;
background-color: #002165;
}

unit_hud_selector, tax_rates_dialog QPushButton:hover {
color: white;

0 comments on commit f1adf62

Please sign in to comment.
You can’t perform that action at this time.