Welcome to mirror list, hosted at ThFree Co, Russian Federation.

preferences_dialog.cpp « qt - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 622f4f377ee812c4cba2de04a2153d49f3fe171e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#include "qt/preferences_dialog.hpp"

#include "platform/settings.hpp"

#include <QtGui/QIcon>

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
  #include <QtGui/QCheckBox>
  #include <QtGui/QHBoxLayout>
  #include <QtGui/QVBoxLayout>
  #include <QtGui/QTableWidget>
  #include <QtGui/QHeaderView>
  #include <QtGui/QPushButton>
  #include <QtGui/QGroupBox>
  #include <QtGui/QButtonGroup>
  #include <QtGui/QRadioButton>
#else
  #include <QtWidgets/QCheckBox>
  #include <QtWidgets/QHBoxLayout>
  #include <QtWidgets/QVBoxLayout>
  #include <QtWidgets/QTableWidget>
  #include <QtWidgets/QHeaderView>
  #include <QtWidgets/QPushButton>
  #include <QtWidgets/QGroupBox>
  #include <QtWidgets/QButtonGroup>
  #include <QtWidgets/QRadioButton>
#endif

namespace qt
{
  PreferencesDialog::PreferencesDialog(QWidget * parent)
  : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint)
  {
    QIcon icon(":/ui/logo.png");
    setWindowIcon(icon);
    setWindowTitle(tr("Preferences"));

    m_pUnits = new QButtonGroup(this);
    QGroupBox * radioBox = new QGroupBox("System of measurement");
    {
      QHBoxLayout * pLayout = new QHBoxLayout();

      using namespace Settings;

      QRadioButton * p = new QRadioButton("Metric");
      pLayout->addWidget(p);
      m_pUnits->addButton(p, Metric);

      p = new QRadioButton("Imperial (foot)");
      pLayout->addWidget(p);
      m_pUnits->addButton(p, Foot);

      radioBox->setLayout(pLayout);

      Units u;
      if (!Settings::Get("Units", u))
      {
        // set default measurement from system locale
        if (QLocale::system().measurementSystem() == QLocale::MetricSystem)
          u = Metric;
        else
          u = Foot;
      }
      m_pUnits->button(static_cast<int>(u))->setChecked(true);

      connect(m_pUnits, SIGNAL(buttonClicked(int)), this, SLOT(OnUnitsChanged(int)));
    }


    QHBoxLayout * bottomLayout = new QHBoxLayout();
    {
      QPushButton * closeButton = new QPushButton(tr("Close"));
      closeButton->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
      closeButton->setDefault(true);
      connect(closeButton, SIGNAL(clicked()), this, SLOT(OnCloseClick()));

      bottomLayout->addStretch(1);
      bottomLayout->setSpacing(0);
      bottomLayout->addWidget(closeButton);
    }

    QVBoxLayout * finalLayout = new QVBoxLayout();
    finalLayout->addWidget(radioBox);
    finalLayout->addLayout(bottomLayout);
    setLayout(finalLayout);
  }

  void PreferencesDialog::OnCloseClick()
  {
    done(0);
  }

  void PreferencesDialog::OnUnitsChanged(int i)
  {
    using namespace Settings;

    Units u;
    switch (i)
    {
    case 0: u = Metric; break;
    case 1: u = Foot; break;
    }

    Settings::Set("Units", u);
  }
}