Add multiple animation paths and details dialog

This commit is contained in:
Tasos Sahanidis
2019-08-17 22:16:11 +03:00
parent 8513a68a8c
commit c4c4123721
9 changed files with 481 additions and 218 deletions
+3
View File
@@ -115,6 +115,7 @@ if (MACOS OR LINUX)
ckb-next
PRIVATE
animadddialog.cpp
animdetailsdialog.cpp
animscript.cpp
animsettingdialog.cpp
autorun.cpp
@@ -158,6 +159,7 @@ if (MACOS OR LINUX)
rlistwidget.cpp
settingswidget.cpp
animadddialog.h
animdetailsdialog.h
animscript.h
animsettingdialog.h
autorun.h
@@ -201,6 +203,7 @@ if (MACOS OR LINUX)
rlistwidget.h
settingswidget.h
animadddialog.ui
animdetailsdialog.ui
animsettingdialog.ui
ckbupdaterwidget.ui
extrasettingswidget.ui
+27
View File
@@ -0,0 +1,27 @@
#include "animdetailsdialog.h"
#include "ui_animdetailsdialog.h"
#include <QTextDocumentFragment>
AnimDetailsDialog::AnimDetailsDialog(QWidget *parent) :
QDialog(parent),
ui(new Ui::AnimDetailsDialog)
{
ui->setupUi(this);
foreach(const AnimScript* script, AnimScript::list()){
int row = ui->animTable->rowCount();
ui->animTable->insertRow(row);
ui->animTable->setItem(row, 0, new QTableWidgetItem(script->name()));
ui->animTable->setItem(row, 1, new QTableWidgetItem(script->path()));
ui->animTable->setItem(row, 2, new QTableWidgetItem(script->version()));
ui->animTable->setItem(row, 3, new QTableWidgetItem(script->author()));
ui->animTable->setItem(row, 4, new QTableWidgetItem(script->year()));
ui->animTable->setItem(row, 5, new QTableWidgetItem(script->license()));
ui->animTable->setItem(row, 6, new QTableWidgetItem(QTextDocumentFragment::fromHtml(script->description()).toPlainText()));
}
ui->animTable->resizeColumnsToContents();
}
AnimDetailsDialog::~AnimDetailsDialog()
{
delete ui;
}
+23
View File
@@ -0,0 +1,23 @@
#ifndef ANIMDETAILSDIALOG_H
#define ANIMDETAILSDIALOG_H
#include <QDialog>
#include "animscript.h"
namespace Ui {
class AnimDetailsDialog;
}
class AnimDetailsDialog : public QDialog
{
Q_OBJECT
public:
explicit AnimDetailsDialog(QWidget *parent = nullptr);
~AnimDetailsDialog();
private:
Ui::AnimDetailsDialog *ui;
};
#endif // ANIMDETAILSDIALOG_H
+130
View File
@@ -0,0 +1,130 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>AnimDetailsDialog</class>
<widget class="QDialog" name="AnimDetailsDialog">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>750</width>
<height>550</height>
</rect>
</property>
<property name="minimumSize">
<size>
<width>750</width>
<height>350</height>
</size>
</property>
<property name="windowTitle">
<string>Loaded Animations</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QTableWidget" name="animTable">
<property name="sizeAdjustPolicy">
<enum>QAbstractScrollArea::AdjustToContentsOnFirstShow</enum>
</property>
<property name="editTriggers">
<set>QAbstractItemView::NoEditTriggers</set>
</property>
<property name="alternatingRowColors">
<bool>true</bool>
</property>
<property name="horizontalScrollMode">
<enum>QAbstractItemView::ScrollPerPixel</enum>
</property>
<property name="showGrid">
<bool>false</bool>
</property>
<property name="columnCount">
<number>7</number>
</property>
<attribute name="horizontalHeaderStretchLastSection">
<bool>true</bool>
</attribute>
<column>
<property name="text">
<string>Name</string>
</property>
</column>
<column>
<property name="text">
<string>Path</string>
</property>
</column>
<column>
<property name="text">
<string>Version</string>
</property>
</column>
<column>
<property name="text">
<string>Author</string>
</property>
</column>
<column>
<property name="text">
<string>Year</string>
</property>
</column>
<column>
<property name="text">
<string>License</string>
</property>
</column>
<column>
<property name="text">
<string>Descripton</string>
</property>
</column>
</widget>
</item>
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="standardButtons">
<set>QDialogButtonBox::Ok</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections>
<connection>
<sender>buttonBox</sender>
<signal>accepted()</signal>
<receiver>AnimDetailsDialog</receiver>
<slot>accept()</slot>
<hints>
<hint type="sourcelabel">
<x>248</x>
<y>254</y>
</hint>
<hint type="destinationlabel">
<x>157</x>
<y>274</y>
</hint>
</hints>
</connection>
<connection>
<sender>buttonBox</sender>
<signal>rejected()</signal>
<receiver>AnimDetailsDialog</receiver>
<slot>reject()</slot>
<hints>
<hint type="sourcelabel">
<x>316</x>
<y>260</y>
</hint>
<hint type="destinationlabel">
<x>286</x>
<y>274</y>
</hint>
</hints>
</connection>
</connections>
</ui>
+34 -10
View File
@@ -6,6 +6,7 @@
#include <QUrl>
#include <ckbnextconfig.h>
#include "animscript.h"
#include <QStandardPaths>
QHash<QUuid, AnimScript*> AnimScript::scripts;
@@ -27,24 +28,47 @@ AnimScript::~AnimScript(){
}
}
QString AnimScript::path(){
return QString(CKB_NEXT_ANIMATIONS_PATH);
QStringList AnimScript::paths(){
QStringList list(CKB_NEXT_ANIMATIONS_PATH);
// Path for when running the GUI from the build dir
#ifdef Q_OS_LINUX
QString appDirPath = QCoreApplication::applicationDirPath();
if(!appDirPath.startsWith("/usr"))
list << appDirPath;
#endif
list << QDir::toNativeSeparators(QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation).append("/ckb-next/animations"));
return list;
}
void AnimScript::scan(){
QDir dir(path());
// Clear old animations
foreach(AnimScript* script, scripts)
delete script;
scripts.clear();
foreach(QString file, dir.entryList(QDir::Files | QDir::Executable)){
AnimScript* script = new AnimScript(qApp, dir.absoluteFilePath(file));
if(script->load() && !scripts.contains(script->_info.guid) && script->presets().count()){
scripts[script->_info.guid] = script;
// Search for animations in all directories, in reverse
// This is done so that the user animation dir takes priority over the system one
for(int i = paths().length() - 1; i >= 0; i--){
QDir dir(paths().at(i));
if(!dir.exists())
continue;
foreach(QString file, dir.entryList(QDir::Files | QDir::Executable)){
#ifdef Q_OS_LINUX
// Ignore the GUI and daemon binaries if loading animations from the build dir
if(file.endsWith("ckb-next") || file.endsWith("ckb-next-daemon"))
continue;
#endif
AnimScript* script = new AnimScript(qApp, dir.absoluteFilePath(file));
if(script->load() && !scripts.contains(script->_info.guid) && script->presets().count()){
scripts[script->_info.guid] = script;
continue;
}
if(!script->presets().count())
qWarning() << script->name() << "has no default preset and will not be loaded.";
delete script;
}
if(!script->presets().count())
qWarning() << script->name() << "has no default preset and will not be loaded.";
delete script;
}
}
+2 -1
View File
@@ -47,7 +47,7 @@ public:
};
// Global animation path
static QString path();
static QStringList paths();
// Scan the animation path for scripts
static void scan();
// Loaded script count and alphabetical list
@@ -67,6 +67,7 @@ public:
inline bool hasKeypress() const { return _info.kpMode != KP_NONE; }
inline const QStringList& presets() const { return _presets; }
inline const PresetValue& preset(int index) const { return _presetValues[index]; }
inline const QString& path() const { return _path; }
// Parameters, in the order they were given
inline QListIterator<Param> paramIterator() const { return _info.params; }
+9 -1
View File
@@ -3,6 +3,7 @@
#include "kb.h"
#include "mainwindow.h"
#include "ckbsettings.h"
#include "animdetailsdialog.h"
// KbLight
static int lastSharedDimming = -2;
@@ -61,7 +62,7 @@ ExtraSettingsWidget::ExtraSettingsWidget(QWidget *parent) :
ui->trayBox->setChecked(settings.value("SuppressTrayIcon").toBool());
// Update animation info
ui->animPathLabel->setText(AnimScript::path());
ui->animPathLabel->setText(AnimScript::paths().join('\n'));
on_animScanButton_clicked();
/// Read Macro Delay setting, update UI and Kb-internal flag
@@ -162,3 +163,10 @@ void ExtraSettingsWidget::on_previewBox_clicked(bool checked)
{
CkbSettings::set("Program/DisablePreviewOnFocusLoss", checked);
}
void ExtraSettingsWidget::on_detailsBtn_clicked()
{
AnimDetailsDialog* dlg = new AnimDetailsDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose, true);
dlg->exec();
}
+2
View File
@@ -30,6 +30,8 @@ private slots:
void on_startDelayBox_clicked(bool checked);
void on_previewBox_clicked(bool checked);
void on_detailsBtn_clicked();
private:
Ui::ExtraSettingsWidget *ui;
};
+251 -206
View File
@@ -29,8 +29,74 @@
<property name="horizontalSpacing">
<number>6</number>
</property>
<item row="1" column="0" colspan="7">
<widget class="Line" name="line">
<item row="3" column="1" colspan="6">
<widget class="QCheckBox" name="brightnessBox">
<property name="toolTip">
<string>By default, the same brightness level will be applied to all profiles and all devices. Enable this to store it with the lighting mode instead.</string>
</property>
<property name="text">
<string>Set brightness per-mode</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="7">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Behavior</string>
</property>
</widget>
</item>
<item row="22" column="0" colspan="7">
<widget class="QLabel" name="osxLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>OS X tweaks</string>
</property>
</widget>
</item>
<item row="18" column="6">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="2" column="1" colspan="6">
<widget class="QCheckBox" name="trayBox">
<property name="toolTip">
<string>The tray icon will not be displayed. The application will still run in the background; re-launch the app to see the GUI again.</string>
</property>
<property name="text">
<string>Hide tray icon</string>
</property>
</widget>
</item>
<item row="23" column="0" colspan="7">
<widget class="Line" name="osxLine">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="16" column="0" colspan="7">
<widget class="Line" name="line_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
@@ -52,23 +118,10 @@
</property>
</spacer>
</item>
<item row="24" column="1" colspan="6">
<widget class="QCheckBox" name="mAccelBox">
<property name="toolTip">
<string>Try this if you're having problems with mouse movement.</string>
</property>
<item row="18" column="1">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Disable mouse acceleration</string>
</property>
</widget>
</item>
<item row="19" column="1" colspan="6">
<widget class="QCheckBox" name="ditherBox">
<property name="toolTip">
<string>May improve appearance on some keyboards.</string>
</property>
<property name="text">
<string>Use spatial dithering to simulate extra color resolution</string>
<string>Frame rate (FPS):</string>
</property>
</widget>
</item>
@@ -88,46 +141,100 @@
</property>
</spacer>
</item>
<item row="9" column="1" colspan="6">
<widget class="QCheckBox" name="previewBox">
<item row="13" column="3" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout" stretch="0,1,0">
<item>
<widget class="QLabel" name="animPathLabel">
<property name="text">
<string>/path/to/animations</string>
</property>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="textInteractionFlags">
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByMouse</set>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_4">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::MinimumExpanding</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>10</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="spacing">
<number>3</number>
</property>
<item>
<widget class="QLabel" name="animCountLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>0 animations found</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QPushButton" name="animScanButton">
<property name="text">
<string>Re-scan</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="detailsBtn">
<property name="text">
<string>Details</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
</layout>
</item>
<item row="13" column="1">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Disable animated preview when ckb-next is not in focus</string>
<string>Location:</string>
</property>
<property name="checked">
<bool>false</bool>
<property name="alignment">
<set>Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop</set>
</property>
<property name="margin">
<number>0</number>
</property>
</widget>
</item>
<item row="12" column="0" colspan="7">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="18" column="6">
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item row="11" column="0" colspan="7">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
<item row="24" column="1" colspan="6">
<widget class="QCheckBox" name="mAccelBox">
<property name="toolTip">
<string>Try this if you're having problems with mouse movement.</string>
</property>
<property name="text">
<string>Animation scripts</string>
<string>Disable mouse acceleration</string>
</property>
</widget>
</item>
@@ -147,55 +254,6 @@
</property>
</spacer>
</item>
<item row="18" column="3">
<widget class="QSpinBox" name="fpsBox">
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>60</number>
</property>
<property name="value">
<number>30</number>
</property>
</widget>
</item>
<item row="20" column="1" colspan="6">
<widget class="QCheckBox" name="delayBox">
<property name="toolTip">
<string>When using macros with strings longer than 25 chars, some OS may lose characters (e.g. Mint 17.2). Select to prevent that bug.</string>
</property>
<property name="text">
<string>Use delay for very long macros</string>
</property>
</widget>
</item>
<item row="4" column="1" colspan="6">
<widget class="QLabel" name="scrollWarningLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Enabling per-mode brightness will disable scrolling on the tray icon to change the brightness level</string>
</property>
</widget>
</item>
<item row="3" column="1" colspan="6">
<widget class="QCheckBox" name="brightnessBox">
<property name="toolTip">
<string>By default, the same brightness level will be applied to all profiles and all devices. Enable this to store it with the lighting mode instead.</string>
</property>
<property name="text">
<string>Set brightness per-mode</string>
</property>
</widget>
</item>
<item row="15" column="0" colspan="7">
<widget class="QLabel" name="label_2">
<property name="font">
@@ -209,29 +267,6 @@
</property>
</widget>
</item>
<item row="25" column="1" colspan="4">
<widget class="QCheckBox" name="sAccelBox">
<property name="toolTip">
<string>Try this if you're having problems with the scroll wheel.</string>
</property>
<property name="text">
<string>Disable scroll acceleration</string>
</property>
</widget>
</item>
<item row="0" column="0" colspan="7">
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Behavior</string>
</property>
</widget>
</item>
<item row="18" column="5">
<widget class="QLabel" name="fpsWarnLabel">
<property name="sizePolicy">
@@ -245,76 +280,6 @@
</property>
</widget>
</item>
<item row="23" column="0" colspan="7">
<widget class="Line" name="osxLine">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="13" column="3" colspan="4">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QLabel" name="animPathLabel">
<property name="text">
<string>/path/to/animations</string>
</property>
</widget>
</item>
<item>
<widget class="QLabel" name="animCountLabel">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>0 animations found</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="animScanButton">
<property name="text">
<string>Re-scan</string>
</property>
</widget>
</item>
</layout>
</item>
<item row="22" column="0" colspan="7">
<widget class="QLabel" name="osxLabel">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>OS X tweaks</string>
</property>
</widget>
</item>
<item row="10" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="25" column="5" colspan="2">
<widget class="QWidget" name="sSpeedWidget" native="true">
<property name="sizePolicy">
@@ -372,27 +337,86 @@
</layout>
</widget>
</item>
<item row="13" column="1">
<widget class="QLabel" name="label_6">
<item row="9" column="1" colspan="6">
<widget class="QCheckBox" name="previewBox">
<property name="text">
<string>Location:</string>
<string>Disable animated preview when ckb-next is not in focus</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item row="16" column="0" colspan="7">
<widget class="Line" name="line_2">
<item row="20" column="1" colspan="6">
<widget class="QCheckBox" name="delayBox">
<property name="toolTip">
<string>When using macros with strings longer than 25 chars, some OS may lose characters (e.g. Mint 17.2). Select to prevent that bug.</string>
</property>
<property name="text">
<string>Use delay for very long macros</string>
</property>
</widget>
</item>
<item row="10" column="1">
<spacer name="verticalSpacer_5">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeType">
<enum>QSizePolicy::Fixed</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
</spacer>
</item>
<item row="1" column="0" colspan="7">
<widget class="Line" name="line">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="2" column="1" colspan="6">
<widget class="QCheckBox" name="trayBox">
<item row="19" column="1" colspan="6">
<widget class="QCheckBox" name="ditherBox">
<property name="toolTip">
<string>The tray icon will not be displayed. The application will still run in the background; re-launch the app to see the GUI again.</string>
<string>May improve appearance on some keyboards.</string>
</property>
<property name="text">
<string>Hide tray icon</string>
<string>Use spatial dithering to simulate extra color resolution</string>
</property>
</widget>
</item>
<item row="25" column="1" colspan="4">
<widget class="QCheckBox" name="sAccelBox">
<property name="toolTip">
<string>Try this if you're having problems with the scroll wheel.</string>
</property>
<property name="text">
<string>Disable scroll acceleration</string>
</property>
</widget>
</item>
<item row="12" column="0" colspan="7">
<widget class="Line" name="line_3">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
</widget>
</item>
<item row="11" column="0" colspan="7">
<widget class="QLabel" name="label_5">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Animation scripts</string>
</property>
</widget>
</item>
@@ -403,10 +427,32 @@
</property>
</widget>
</item>
<item row="18" column="1">
<widget class="QLabel" name="label_3">
<item row="18" column="3">
<widget class="QSpinBox" name="fpsBox">
<property name="minimum">
<number>5</number>
</property>
<property name="maximum">
<number>60</number>
</property>
<property name="value">
<number>30</number>
</property>
</widget>
</item>
<item row="4" column="1" colspan="6">
<widget class="QLabel" name="scrollWarningLabel">
<property name="enabled">
<bool>true</bool>
</property>
<property name="font">
<font>
<pointsize>8</pointsize>
<italic>true</italic>
</font>
</property>
<property name="text">
<string>Frame rate (FPS):</string>
<string>Enabling per-mode brightness will disable scrolling on the tray icon to change the brightness level</string>
</property>
</widget>
</item>
@@ -415,7 +461,6 @@
<tabstops>
<tabstop>trayBox</tabstop>
<tabstop>brightnessBox</tabstop>
<tabstop>animScanButton</tabstop>
<tabstop>fpsBox</tabstop>
<tabstop>ditherBox</tabstop>
<tabstop>delayBox</tabstop>