Skip to content

Commit

Permalink
Merge pull request #20 from lirios/release-1.0
Browse files Browse the repository at this point in the history
Release 1.0
  • Loading branch information
pierremtb authored May 11, 2017
2 parents 2aff224 + f380755 commit 43a636b
Show file tree
Hide file tree
Showing 16 changed files with 339 additions and 313 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ QuotaManager
QuotaManager-journal
TransportSecurity
databases/

build/
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ script:
- rm ./appdir/io.liri.Calculator.png # Workaround for linuxedeloyqt bug
- ./linuxdeployqt*.AppImage ./appdir/usr/share/applications/*.desktop -appimage -qmldir=. -verbose=2
- find ./appdir -executable -type f -exec ldd {} \; | grep " => /usr" | cut -d " " -f 2-3 | sort | uniq
- curl --upload-file ./Liri_Calculator*.AppImage https://transfer.sh/Liri_Calculator-git.$(git rev-parse --short HEAD)-x86_64.AppImage
- curl --upload-file ./Liri_Calculator*.AppImage https://transfer.sh/Liri_Calculator-git-$(date +%Y%m%d-%H%M%S)-$(git rev-parse --short HEAD)-x86_64.AppImage
3 changes: 2 additions & 1 deletion liri-calculator.pro
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ ICON += $$PWD/src/icons/liri-calculator.icns

RESOURCES += \
$$PWD/src/engine/engine.qrc \
$$PWD/src/ui/ui.qrc
$$PWD/src/ui/ui.qrc \
$$PWD/src/icons/icons.qrc

unix:!android {
target.path = $$LIRI_INSTALL_BINDIR
Expand Down
69 changes: 2 additions & 67 deletions src/filehandler/filehandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
#include <QTextDocument>

FileHandler::FileHandler(QObject *parent):QObject(parent),
m_document(nullptr),
m_cursorPosition(-1),
m_selectionStart(0),
m_selectionEnd(0) {}
m_document(nullptr){}

QQuickTextDocument *FileHandler::document() const {
return m_document;
Expand All @@ -29,50 +26,11 @@ void FileHandler::setDocument(QQuickTextDocument *document) {
emit documentChanged();
}

int FileHandler::cursorPosition() const {
return m_cursorPosition;
}

void FileHandler::setCursorPosition(int position) {
if (position == m_cursorPosition) {
return;
}

m_cursorPosition = position;
emit cursorPositionChanged();
}

int FileHandler::selectionStart() const{
return m_selectionStart;
}

void FileHandler::setSelectionStart(int position){
if (position == m_selectionStart) {
return;
}

m_selectionStart = position;
emit selectionStartChanged();
}

int FileHandler::selectionEnd() const {
return m_selectionEnd;
}

void FileHandler::setSelectionEnd(int position) {
if (position == m_selectionEnd) {
return;
}

m_selectionEnd = position;
emit selectionEndChanged();
}

QString FileHandler::fileName() const {
const QString filePath = QQmlFile::urlToLocalFileOrQrc(m_fileUrl);
const QString fileName = QFileInfo(filePath).fileName();
if (fileName.isEmpty()) {
return QStringLiteral("untitled.txt");
return QStringLiteral("untitled.lcs");
}
return fileName;
}
Expand Down Expand Up @@ -137,33 +95,10 @@ void FileHandler::saveAs(const QUrl &fileUrl) {
emit fileUrlChanged();
}

QTextCursor FileHandler::textCursor() const {
QTextDocument *doc = textDocument();
if (!doc)
return QTextCursor();

QTextCursor cursor = QTextCursor(doc);
if (m_selectionStart != m_selectionEnd) {
cursor.setPosition(m_selectionStart);
cursor.setPosition(m_selectionEnd, QTextCursor::KeepAnchor);
} else {
cursor.setPosition(m_cursorPosition);
}
return cursor;
}

QTextDocument *FileHandler::textDocument() const {
if (!m_document) {
return nullptr;
}

return m_document->textDocument();
}

void FileHandler::mergeFormatOnWordOrSelection(const QTextCharFormat &format) {
QTextCursor cursor = textCursor();
if (!cursor.hasSelection()) {
cursor.select(QTextCursor::WordUnderCursor);
}
cursor.mergeCharFormat(format);
}
29 changes: 0 additions & 29 deletions src/filehandler/filehandler.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#ifndef FILEHANDLER_H
#define FILEHANDLER_H

#include <QFont>
#include <QObject>
#include <QTextCursor>
#include <QUrl>

QT_BEGIN_NAMESPACE
Expand All @@ -16,10 +14,6 @@ class FileHandler : public QObject
Q_OBJECT

Q_PROPERTY(QQuickTextDocument *document READ document WRITE setDocument NOTIFY documentChanged)
Q_PROPERTY(int cursorPosition READ cursorPosition WRITE setCursorPosition NOTIFY cursorPositionChanged)
Q_PROPERTY(int selectionStart READ selectionStart WRITE setSelectionStart NOTIFY selectionStartChanged)
Q_PROPERTY(int selectionEnd READ selectionEnd WRITE setSelectionEnd NOTIFY selectionEndChanged)

Q_PROPERTY(QString fileName READ fileName NOTIFY fileUrlChanged)
Q_PROPERTY(QString fileType READ fileType NOTIFY fileUrlChanged)
Q_PROPERTY(QUrl fileUrl READ fileUrl NOTIFY fileUrlChanged)
Expand All @@ -29,16 +23,6 @@ class FileHandler : public QObject

QQuickTextDocument *document() const;
void setDocument(QQuickTextDocument *document);

int cursorPosition() const;
void setCursorPosition(int position);

int selectionStart() const;
void setSelectionStart(int position);

int selectionEnd() const;
void setSelectionEnd(int position);

QString fileName() const;
QString fileType() const;
QUrl fileUrl() const;
Expand All @@ -49,27 +33,14 @@ public Q_SLOTS:

Q_SIGNALS:
void documentChanged();
void cursorPositionChanged();
void selectionStartChanged();
void selectionEndChanged();

void textChanged();
void fileUrlChanged();

void loaded(const QString &text);
void error(const QString &message);

private:
QTextCursor textCursor() const;
QTextDocument *textDocument() const;
void mergeFormatOnWordOrSelection(const QTextCharFormat &format);

QQuickTextDocument *m_document;

int m_cursorPosition;
int m_selectionStart;
int m_selectionEnd;

QUrl m_fileUrl;
};

Expand Down
Binary file added src/icons/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions src/icons/icons.qrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<RCC>
<qresource prefix="/icons">
<file>icon.png</file>
</qresource>
</RCC>
6 changes: 6 additions & 0 deletions src/main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

#include <QtGlobal>
#include <QGuiApplication>
#include <QIcon>
#include <QQmlApplicationEngine>
#include <QtQuickControls2/QQuickStyle>
#include <QQmlContext>
Expand All @@ -38,6 +39,11 @@ int main(int argc, char *argv[])
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

QGuiApplication app(argc, argv);
app.setOrganizationName(QLatin1String("Liri"));
app.setOrganizationDomain(QLatin1String("liri.io"));
app.setApplicationName(QLatin1String("Calculator"));
app.setDesktopFileName(QLatin1String("io.liri.Calculator.desktop"));
app.setWindowIcon(QIcon("qrc:/icons/icon.png"));

// create qml app engine
QQmlApplicationEngine engine;
Expand Down
3 changes: 2 additions & 1 deletion src/ui/ButtonsPanel.qml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,11 @@ import "../engine"

Rectangle {
id: buttonsPanel
Component.onCompleted: updateHeight()

property alias computedHeight: fns.height

height: computedHeight

Row {
anchors.fill: parent

Expand Down
2 changes: 1 addition & 1 deletion src/ui/ButtonsView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ Rectangle {

Label {
text: modelData
width: 64
width: root.width / 8
topPadding: Units.smallSpacing / 2
bottomPadding: Units.smallSpacing / 2
horizontalAlignment: Qt.AlignHCenter
Expand Down
103 changes: 103 additions & 0 deletions src/ui/CalculationLine.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.0
import QtQuick.Controls.Material 2.0
import Fluid.Controls 1.0
import Fluid.Material 1.0


Column {
width: root.width
padding: Units.smallSpacing
spacing: Units.smallSpacing

Row {
width: parent.width
height: formulaEdit.height
spacing: Units.smallSpacing

TextEdit {
id: formulaEdit
text: formula
width: (root.width - 3 * Units.smallSpacing) * 2/3
font.pointSize: root.styles.advancedFontSize
opacity: root.styles.secondaryTextOpacity
selectByMouse: true
wrapMode: TextEdit.WrapAnywhere
onTextChanged: {
formula = text;
var calculations = [];
for (var i=0; i<calculationsRepeater.model.count; i++) {
calculations.push(calculationsRepeater.model.get(i).formula);
}
var results = calculate(calculations, true);
for (var i=0; i<calculationsRepeater.model.count; i++) {
calculationsRepeater.model.setProperty( i, 'result', results[i] + '');
}
syncTextDocument();
}
Keys.onDownPressed: {
if (index < calculationsRepeater.model.count - 1) {
setFocusAt(index + 1)
}
}
Keys.onUpPressed: {
if (index > 0) {
setFocusAt(index - 1)
}
}
Keys.onPressed: {
switch (event.key) {
case Qt.Key_Enter:
case Qt.Key_Return:
event.accepted = true;
calculationsRepeater.model.insert(index + 1,{ formula: '', result: '' });
setFocusAt(index + 1);
if (index + 2 === calculationsRepeater.model.count && advancedView.contentHeight >= advancedView.height) {
advancedView.contentY = advancedView.contentHeight - advancedView.height;
}
break;
case Qt.Key_Backspace:
if (index > 0 && event.key === Qt.Key_Backspace && text === '') {
setFocusAt(index - 1);
calculationsRepeater.model.remove(index, 1);
}
break;
default: return;
}
}
}

Text {
id: formulaResult
text: hasError ? qsTr('Error') : formula === '' ? '' : result
color: hasError ? 'red' : 'black'
height: formulaEdit.height
opacity: hasError ? root.styles.hintTextOpacity : root.styles.primaryTextOpacity
width: (root.width - 3 * Units.smallSpacing) * 1/3
font.pointSize: root.styles.advancedFontSize
horizontalAlignment: Text.AlignRight
clip: true
wrapMode: TextEdit.NoWrap
font.italic: hasError
verticalAlignment: Qt.AlignBottom

property bool hasError: result === 'undefined' && formula !== ''

MouseArea {
visible: parent.hasError
enabled: parent.hasError
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: snackBar.open(root.lastError)
}
}
}

Rectangle {
width: root.width - 2 * Units.smallSpacing
height: 1
color: formulaResult.hasError ? 'red' : 'black'
opacity: 0.1
}
}
Loading

0 comments on commit 43a636b

Please sign in to comment.