Commit 1c53dba3 authored by Christian Rüb's avatar Christian Rüb

provide own numpad and desktop files

parent 9d02ac0b
[Desktop Entry]
Name=QCurrency
Comment=Currency Calculator
Exec=qcurrency -stylesheet /usr/share/qcurrency/shr.style
Icon=qcurrency
Terminal=false
Type=Application
Categories=Applications;
StartupNotify=true
......@@ -3,26 +3,27 @@
# -------------------------------------------------
TARGET = qcurrency
TEMPLATE = app
linux-gnueabi-oe-g++ {
message(" building for ARM")
OBJECTS_DIR = build
MOC_DIR = build
UI_HEADERS_DIR = build
UI_SOURCES_DIR = build
linux-gnueabi-oe-g++ {
message(" building for ARM")
OBJECTS_DIR = build
MOC_DIR = build
UI_HEADERS_DIR = build
UI_SOURCES_DIR = build
}
else {
message("building for x86")
OBJECTS_DIR = build.x86
MOC_DIR = build.x86
UI_HEADERS_DIR = build.x86
UI_SOURCES_DIR = build.x86
TARGET = qcurrency.x86
MAKEFILE += Makefile.x86
else {
message("building for x86")
OBJECTS_DIR = build.x86
MOC_DIR = build.x86
UI_HEADERS_DIR = build.x86
UI_SOURCES_DIR = build.x86
TARGET = qcurrency.x86
MAKEFILE += Makefile.x86
}
SOURCES += src/main.cpp \
src/qcurrency.cpp
HEADERS += src/qcurrency.h
FORMS += ui/qcurrency.ui
src/qcurrency.cpp \
src/numpad.cpp
HEADERS += src/qcurrency.h \
src/numpad.h
FORMS += ui/qcurrency.ui \
ui/numpad.ui
OTHER_FILES += styles/shr.style
#include "numpad.h"
#include "ui_numpad.h"
NumPad::NumPad(QWidget *parent) :
QWidget(parent),
m_ui(new Ui::NumPad)
{
m_ui->setupUi(this);
signalMapper = new QSignalMapper(this);
//connections
connect(m_ui->oneButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->twoButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->threeButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->fourButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->fiveButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->sixButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->sevenButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->eightButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->nineButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->zeroButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->dotButton, SIGNAL(clicked()), signalMapper, SLOT(map()));
connect(m_ui->backButton, SIGNAL(clicked()), this, SIGNAL(delClicked()));
//set up mapping
signalMapper->setMapping(m_ui->oneButton, "1");
signalMapper->setMapping(m_ui->twoButton, "2");
signalMapper->setMapping(m_ui->threeButton, "3");
signalMapper->setMapping(m_ui->fourButton, "4");
signalMapper->setMapping(m_ui->fiveButton, "5");
signalMapper->setMapping(m_ui->sixButton, "6");
signalMapper->setMapping(m_ui->sevenButton, "7");
signalMapper->setMapping(m_ui->eightButton, "8");
signalMapper->setMapping(m_ui->nineButton, "9");
signalMapper->setMapping(m_ui->zeroButton, "0");
signalMapper->setMapping(m_ui->dotButton, ".");
//connect mapped signals
connect(signalMapper, SIGNAL(mapped(const QString)), this, SIGNAL(clicked(const QString)));
}
NumPad::~NumPad()
{
delete m_ui;
}
void NumPad::changeEvent(QEvent *e)
{
QWidget::changeEvent(e);
switch (e->type()) {
case QEvent::LanguageChange:
m_ui->retranslateUi(this);
break;
default:
break;
}
}
#ifndef NUMPAD_H
#define NUMPAD_H
#include <QSignalMapper>
#include <QtGui/QWidget>
namespace Ui {
class NumPad;
}
class NumPad : public QWidget {
Q_OBJECT
public:
NumPad(QWidget *parent = 0);
~NumPad();
protected:
void changeEvent(QEvent *e);
private:
Ui::NumPad *m_ui;
QSignalMapper *signalMapper;
signals:
void clicked(QString);
void delClicked();
};
#endif // NUMPAD_H
#include "qcurrency.h"
#include "ui_qcurrency.h"
#include <QDebug>
#include <QDoubleValidator>
QCurrency::QCurrency(QWidget *parent)
: QMainWindow(parent), ui(new Ui::QCurrency) {
ui->setupUi(this);
ui->rateEdit->setValidator(new QDoubleValidator(0,1000000,10,this));
ui->valueEdit->setValidator(new QDoubleValidator(0,1000000,10,this));
settings = new QSettings("QCurrency","QCurrency");
rate = 1.0;
connect(ui->exitButton, SIGNAL(clicked()), this, SLOT(close()));
connect(ui->rateEdit, SIGNAL(textChanged(QString)), this, SLOT(setRate(QString)));
connect(ui->valueEdit, SIGNAL(returnPressed()), this, SLOT(calculateRate()));
connect(ui->calcButton, SIGNAL(clicked()), this, SLOT(calculateRate()));
connect(ui->rateEdit, SIGNAL(editingFinished()), this, SLOT(updateRate()));
connect(ui->valueEdit, SIGNAL(returnPressed()), this, SLOT(calculateResult()));
connect(ui->calcButton, SIGNAL(clicked()), this, SLOT(calculateResult()));
connect(ui->numPad, SIGNAL(clicked(QString)), this, SLOT(appendString(QString)));
connect(ui->numPad, SIGNAL(delClicked()), this, SLOT(backspace()));
connect(ui->saveRateButton, SIGNAL(clicked()), this, SLOT(saveSettings()));
connect(ui->exitButton, SIGNAL(clicked()), this, SLOT(close()));
ui->rateEdit->setText(QString::number(rate));
ui->valueEdit->setFocus();
}
QCurrency::~QCurrency() {
......@@ -22,12 +29,14 @@ QCurrency::~QCurrency() {
delete settings;
}
void QCurrency::calculateRate() {
void QCurrency::calculateResult() {
bool ok;
double val = ui->valueEdit->text().toDouble(&ok);
if(ok) {
ui->toEdit->setText(QString::number((val / rate),'f',2));
ui->fromEdit->setText(QString::number((val * rate),'f',2));
} else {
ui->valueEdit->clear();
}
}
......@@ -40,11 +49,35 @@ void QCurrency::loadSettings() {
ui->rateEdit->setText(QString::number(rate));
}
void QCurrency::setRate(QString newrate) {
bool QCurrency::setRate(double newrate) {
if(newrate > 0.0) {
rate = newrate;
return true;
}
return false;
}
void QCurrency::updateRate() {
bool ok;
double retval = newrate.toDouble(&ok);
double editval = ui->rateEdit->text().toDouble(&ok);
if(ok) {
rate = retval;
qDebug() << "new rate:" << rate;
rate = editval;
ui->rateEdit->setText(QString::number(rate,'f'));
}
}
void QCurrency::appendString(const QString str) {
if(ui->rateEdit->hasFocus()) {
ui->rateEdit->insert(str);
} else if (ui->valueEdit->hasFocus()) {
ui->valueEdit->insert(str);
}
}
void QCurrency::backspace() {
if(ui->rateEdit->hasFocus()) {
ui->rateEdit->backspace();
} else if (ui->valueEdit->hasFocus()) {
ui->valueEdit->backspace();
}
}
......@@ -16,6 +16,7 @@ public:
~QCurrency();
void loadSettings();
bool setRate(double);
private:
Ui::QCurrency *ui;
......@@ -23,9 +24,11 @@ private:
double rate;
private slots:
void calculateRate();
void calculateResult();
void saveSettings();
void setRate(QString);
void updateRate();
void backspace();
void appendString(const QString);
};
#endif // QCURRENCY_H
* {font-size: 20px;}
* {font-size: 25px;}
QPushButton {
font-size: 25px;
font-size: 35px;
border-radius: 8px;
color: #ffffff;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #909090, stop: 0.49 #909090, stop: 0.5 #000000, stop: 1 #000000);
......@@ -9,6 +9,6 @@ QPushButton:disabled {
color: #000000;
background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #d6d7da, stop: 1 #c6c7ca);
}
QPushButton#calcButton, QPushButton#exitButton {
font-size: 35px;
QPushButton#calcButton {
font-size: 50px;
}
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>NumPad</class>
<widget class="QWidget" name="NumPad">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QPushButton" name="oneButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>1</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="twoButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>2</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="fourButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>4</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="fiveButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>5</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="sixButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>6</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QPushButton" name="sevenButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>7</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="eightButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>8</string>
</property>
</widget>
</item>
<item row="3" column="0">
<widget class="QPushButton" name="zeroButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>0</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="dotButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>.</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="backButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>&lt;-</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="nineButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>9</string>
</property>
</widget>
</item>
<item row="0" column="2">
<widget class="QPushButton" name="threeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Minimum">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>3</string>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -15,6 +15,9 @@
</property>
<widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout">
<property name="margin">
<number>0</number>
</property>
<item row="0" column="0">
<widget class="QLabel" name="rateLabel">
<property name="text">
......@@ -22,16 +25,9 @@
</property>
</widget>
</item>
<item row="0" column="1">
<item row="0" column="2">
<widget class="QLineEdit" name="rateEdit"/>
</item>
<item row="1" column="0">
<widget class="QPushButton" name="saveRateButton">
<property name="text">
<string>Save rate</string>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="valueLabel">
<property name="text">
......@@ -39,7 +35,7 @@
</property>
</widget>
</item>
<item row="2" column="1">
<item row="2" column="2">
<widget class="QLineEdit" name="valueEdit"/>
</item>
<item row="3" column="0">
......@@ -49,8 +45,12 @@
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QLineEdit" name="toEdit"/>
<item row="3" column="2">
<widget class="QLineEdit" name="toEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="fromButton">
......@@ -59,17 +59,40 @@
</property>
</widget>
</item>
<item row="4" column="1">
<widget class="QLineEdit" name="fromEdit"/>
<item row="4" column="2">
<widget class="QLineEdit" name="fromEdit">
<property name="readOnly">
<bool>true</bool>
</property>
</widget>
</item>
<item row="5" column="0" colspan="2">
<item row="5" column="0" colspan="3">
<widget class="QPushButton" name="calcButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="focusPolicy">
<enum>Qt::NoFocus</enum>
</property>
<property name="text">
<string>Calculate</string>
</property>
</widget>
</item>
<item row="6" column="0" colspan="2">
<item row="6" column="0" colspan="3">
<widget class="NumPad" name="numPad" native="true"/>
</item>
<item row="7" column="0" colspan="2">
<widget class="QPushButton" name="saveRateButton">
<property name="text">
<string>Save rate</string>
</property>
</widget>
</item>
<item row="7" column="2">
<widget class="QPushButton" name="exitButton">
<property name="text">
<string>Exit</string>
......@@ -80,6 +103,14 @@
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<customwidgets>
<customwidget>
<class>NumPad</class>
<extends>QWidget</extends>
<header>src/numpad.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>
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