mirror of
https://github.com/Quill-OS/quill.git
synced 2024-12-26 23:57:22 -08:00
First steps to control brightness from MainWindow and show battery
level/status
This commit is contained in:
parent
ccf67053df
commit
d3362890be
5 changed files with 179 additions and 129 deletions
1
eink.qrc
1
eink.qrc
|
@ -30,5 +30,6 @@
|
|||
<file>resources/battery_charging.png</file>
|
||||
<file>resources/alert.png</file>
|
||||
<file>resources/eink_dark.qss</file>
|
||||
<file>resources/frontlight.png</file>
|
||||
</qresource>
|
||||
</RCC>
|
||||
|
|
|
@ -30,12 +30,14 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
ui->quitBtn->setProperty("type", "borderless");
|
||||
ui->searchBtn->setProperty("type", "borderless");
|
||||
ui->pushButton->setProperty("type", "borderless");
|
||||
ui->brightnessBtn->setProperty("type", "borderless");
|
||||
|
||||
ui->settingsBtn->setText("");
|
||||
ui->appsBtn->setText("");
|
||||
ui->pushButton->setText("");
|
||||
ui->quitBtn->setText("");
|
||||
ui->searchBtn->setText("");
|
||||
ui->brightnessBtn->setText("");
|
||||
|
||||
// Getting the screen's size
|
||||
float sW = QGuiApplication::screens()[0]->size().width();
|
||||
|
@ -44,15 +46,21 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
|
||||
float stdIconWidth;
|
||||
float stdIconHeight;
|
||||
float brightnessIconWidth;
|
||||
float brightnessIconHeight;
|
||||
|
||||
string_checkconfig("/opt/inkbox_device");
|
||||
if(checkconfig_str_val == "n705\n") {
|
||||
stdIconWidth = sW / 12;
|
||||
stdIconHeight = sH / 12;
|
||||
brightnessIconWidth = sW / 30;
|
||||
brightnessIconHeight = sH / 30;
|
||||
}
|
||||
else {
|
||||
stdIconWidth = sW / 14;
|
||||
stdIconHeight = sH / 14;
|
||||
brightnessIconWidth = sW / 28;
|
||||
brightnessIconHeight = sH / 28;
|
||||
}
|
||||
|
||||
// Setting icons up
|
||||
|
@ -67,11 +75,18 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
ui->quitBtn->setIcon(QIcon(":/resources/power.png"));
|
||||
ui->quitBtn->setIconSize(QSize(stdIconWidth, stdIconHeight));
|
||||
|
||||
ui->brightnessBtn->setIcon(QIcon(":/resources/frontlight.png"));
|
||||
ui->brightnessBtn->setIconSize(QSize(brightnessIconWidth, brightnessIconHeight));
|
||||
|
||||
ui->book1Btn->setStyleSheet("font-size: 11pt; padding: 25px");
|
||||
ui->book2Btn->setStyleSheet("font-size: 11pt; padding: 25px");
|
||||
ui->book3Btn->setStyleSheet("font-size: 11pt; padding: 25px");
|
||||
ui->book4Btn->setStyleSheet("font-size: 11pt; padding: 25px");
|
||||
|
||||
ui->brightnessBtn->setStyleSheet("font-size: 9pt; padding-bottom: 5px; padding-top: 5px; padding-left: 10px; padding-right: 10px;");
|
||||
ui->batteryIcon->setStyleSheet("font-size: 5pt");
|
||||
ui->batteryIcon->setText("");
|
||||
|
||||
ui->book1Btn->hide();
|
||||
ui->book2Btn->hide();
|
||||
ui->book3Btn->hide();
|
||||
|
@ -167,10 +182,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(500);
|
||||
connect(t, &QTimer::timeout, [&]() {
|
||||
QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
||||
QString time = QTime::currentTime().toString("hh:mm:ss");
|
||||
get_battery_level();
|
||||
ui->timeLabel->setText(time);
|
||||
ui->dateLabel->setText(date);
|
||||
ui->batteryLabel->setText(batt_level);
|
||||
} );
|
||||
t->start();
|
||||
}
|
||||
|
@ -178,10 +193,10 @@ MainWindow::MainWindow(QWidget *parent)
|
|||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(500);
|
||||
connect(t, &QTimer::timeout, [&]() {
|
||||
QString date = QDateTime::currentDateTime().toString("yyyy-MM-dd");
|
||||
QString time = QTime::currentTime().toString("hh:mm");
|
||||
get_battery_level();
|
||||
ui->timeLabel->setText(time);
|
||||
ui->dateLabel->setText(date);
|
||||
ui->batteryLabel->setText(batt_level);
|
||||
} );
|
||||
t->start();
|
||||
}
|
||||
|
|
11
mainwindow.h
11
mainwindow.h
|
@ -26,8 +26,10 @@ public:
|
|||
bool checked_box = false;
|
||||
bool existing_recent_books = false;
|
||||
bool reboot_after_update = false;
|
||||
int batt_level_int;
|
||||
QString checkconfig_str_val;
|
||||
QString relative_path;
|
||||
QString batt_level;
|
||||
bool checkconfig(QString file) {
|
||||
QFile config(file);
|
||||
config.open(QIODevice::ReadOnly);
|
||||
|
@ -48,6 +50,15 @@ public:
|
|||
fhandler << config << boolalpha << checked_box << endl;
|
||||
fhandler.close();
|
||||
}
|
||||
void get_battery_level() {
|
||||
QFile batt_level_file("/sys/devices/platform/pmic_battery.1/power_supply/mc13892_bat/capacity");
|
||||
batt_level_file.open(QIODevice::ReadOnly);
|
||||
batt_level = batt_level_file.readAll();
|
||||
batt_level = batt_level.trimmed();
|
||||
batt_level_int = batt_level.toInt();
|
||||
batt_level = batt_level.append("%");
|
||||
batt_level_file.close();
|
||||
}
|
||||
int brightness_checkconfig(QString file) {
|
||||
QFile config(file);
|
||||
config.open(QIODevice::ReadWrite);
|
||||
|
|
273
mainwindow.ui
273
mainwindow.ui
|
@ -17,34 +17,50 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<item row="0" column="6">
|
||||
<widget class="QPushButton" name="brightnessBtn">
|
||||
<property name="text">
|
||||
<string>Brightness</string>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="5">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="inkboxLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
</font>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
<property name="text">
|
||||
<string>Welcome to InkBox</string>
|
||||
</property>
|
||||
</spacer>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="4">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<item row="0" column="9">
|
||||
<widget class="QLabel" name="batteryLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>batteryLevel</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="8">
|
||||
<widget class="QLabel" name="batteryIcon">
|
||||
<property name="text">
|
||||
<string>batteryIcon</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>―</string>
|
||||
</property>
|
||||
|
@ -67,39 +83,46 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="3">
|
||||
<widget class="QLabel" name="inkboxLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
</font>
|
||||
<item row="0" column="1">
|
||||
<spacer name="horizontalSpacer">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Welcome to InkBox</string>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="2">
|
||||
<widget class="QLabel" name="label">
|
||||
<item row="0" column="4">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>―</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="6">
|
||||
<widget class="QLabel" name="dateLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<pointsize>11</pointsize>
|
||||
<weight>75</weight>
|
||||
<bold>true</bold>
|
||||
</font>
|
||||
<item row="0" column="5">
|
||||
<spacer name="horizontalSpacer_2">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Horizontal</enum>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>date</string>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>40</width>
|
||||
<height>20</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="0" column="7">
|
||||
<widget class="Line" name="line_7">
|
||||
<property name="frameShadow">
|
||||
<enum>QFrame::Plain</enum>
|
||||
</property>
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
|
@ -140,22 +163,6 @@
|
|||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<layout class="QGridLayout" name="gridLayout_3">
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="recentBooksLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Chivo</family>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Recently read books will appear here.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="2" column="0">
|
||||
<spacer name="verticalSpacer_5">
|
||||
<property name="orientation">
|
||||
|
@ -185,6 +192,84 @@
|
|||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="3" column="0">
|
||||
<widget class="QLabel" name="recentBooksLabel">
|
||||
<property name="font">
|
||||
<font>
|
||||
<family>Chivo</family>
|
||||
<italic>true</italic>
|
||||
</font>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string>Recently read books will appear here.</string>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="book1Btn">
|
||||
<property name="text">
|
||||
<string>Book 1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="book2Btn">
|
||||
<property name="text">
|
||||
<string>Book 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_8">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="book3Btn">
|
||||
<property name="text">
|
||||
<string>Book 3</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="book4Btn">
|
||||
<property name="text">
|
||||
<string>Book 4</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="5" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_4">
|
||||
<property name="bottomMargin">
|
||||
|
@ -277,68 +362,6 @@
|
|||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="4" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_6">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="book1Btn">
|
||||
<property name="text">
|
||||
<string>Book 1</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="book2Btn">
|
||||
<property name="text">
|
||||
<string>Book 2</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<layout class="QGridLayout" name="gridLayout_8">
|
||||
<property name="bottomMargin">
|
||||
<number>0</number>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QPushButton" name="book3Btn">
|
||||
<property name="text">
|
||||
<string>Book 3</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QPushButton" name="book4Btn">
|
||||
<property name="text">
|
||||
<string>Book 4</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item row="0" column="0">
|
||||
<spacer name="verticalSpacer_4">
|
||||
<property name="orientation">
|
||||
<enum>Qt::Vertical</enum>
|
||||
</property>
|
||||
<property name="sizeHint" stdset="0">
|
||||
<size>
|
||||
<width>20</width>
|
||||
<height>40</height>
|
||||
</size>
|
||||
</property>
|
||||
</spacer>
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
|
|
BIN
resources/frontlight.png
Normal file
BIN
resources/frontlight.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.3 KiB |
Loading…
Reference in a new issue