diff --git a/CMakeLists.txt b/CMakeLists.txt
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -88,6 +88,7 @@ add_executable(${PROGRAM_NAME} WIN32
commandedit.cpp
dataformatpanel.cpp
tooltipfilter.cpp
+ sneakylineedit.cpp
${UI_FILES}
${RES_FILES}
misc/windows_icon.rc
diff --git a/commandpanel.cpp b/commandpanel.cpp
--- a/commandpanel.cpp
+++ b/commandpanel.cpp
@@ -38,6 +38,7 @@ CommandPanel::CommandPanel(QSerialPort*
connect(ui->pbNew, &QPushButton::clicked, this, &CommandPanel::newCommand);
+ command_name_counter = 0;
newCommand(); // add an empty slot by default
}
@@ -49,6 +50,8 @@ CommandPanel::~CommandPanel()
void CommandPanel::newCommand()
{
auto command = new CommandWidget();
+ command_name_counter++;
+ command->setName(trUtf8("Command ") + QString::number(command_name_counter));
ui->scrollAreaWidgetContents->layout()->addWidget(command);
connect(command, &CommandWidget::sendCommand, this, &CommandPanel::sendCommand);
}
diff --git a/commandpanel.h b/commandpanel.h
--- a/commandpanel.h
+++ b/commandpanel.h
@@ -42,6 +42,8 @@ private:
Ui::CommandPanel *ui;
QSerialPort* serialPort;
+ unsigned command_name_counter;
+
private slots:
void newCommand();
void sendCommand(QByteArray command);
diff --git a/commandwidget.cpp b/commandwidget.cpp
--- a/commandwidget.cpp
+++ b/commandwidget.cpp
@@ -93,3 +93,13 @@ bool CommandWidget::isASCIIMode()
{
return ui->pbASCII->isChecked();
}
+
+void CommandWidget::setName(QString name)
+{
+ ui->leName->setText(name);
+}
+
+QString CommandWidget::name()
+{
+ return ui->leName->text();
+}
diff --git a/commandwidget.h b/commandwidget.h
--- a/commandwidget.h
+++ b/commandwidget.h
@@ -35,6 +35,9 @@ public:
explicit CommandWidget(QWidget *parent = 0);
~CommandWidget();
+ void setName(QString name);
+ QString name();
+
signals:
void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked
diff --git a/commandwidget.ui b/commandwidget.ui
--- a/commandwidget.ui
+++ b/commandwidget.ui
@@ -48,6 +48,9 @@
-
+
+
+ -
@@ -167,6 +170,11 @@
QLineEdit
+
+ SneakyLineEdit
+ QLineEdit
+
+
diff --git a/serialplot.pro b/serialplot.pro
--- a/serialplot.pro
+++ b/serialplot.pro
@@ -51,7 +51,8 @@ SOURCES += main.cpp\
commandwidget.cpp \
commandedit.cpp \
dataformatpanel.cpp \
- tooltipfilter.cpp
+ tooltipfilter.cpp \
+ sneakylineedit.cpp
HEADERS += mainwindow.h \
utils.h \
@@ -72,7 +73,8 @@ HEADERS += mainwindow.h \
commandwidget.h \
commandedit.h \
dataformatpanel.h \
- tooltipfilter.h
+ tooltipfilter.h \
+ sneakylineedit.h
FORMS += mainwindow.ui \
about_dialog.ui \
diff --git a/sneakylineedit.cpp b/sneakylineedit.cpp
new file mode 100644
--- /dev/null
+++ b/sneakylineedit.cpp
@@ -0,0 +1,33 @@
+#include "sneakylineedit.h"
+#include
+
+SneakyLineEdit::SneakyLineEdit(QWidget *parent) :
+ QLineEdit(parent)
+{
+ setFrame(false);
+ setStyleSheet("QLineEdit{background-color: rgba(0,0,0,0);}");
+ setToolTip(trUtf8("Click to edit"));
+
+ setBold(true);
+}
+
+void SneakyLineEdit::focusInEvent(QFocusEvent *event)
+{
+ setFrame(true);
+ setBold(false);
+ QLineEdit::focusInEvent(event);
+}
+
+void SneakyLineEdit::focusOutEvent(QFocusEvent *event)
+{
+ setFrame(false);
+ setBold(true);
+ QLineEdit::focusOutEvent(event);
+}
+
+void SneakyLineEdit::setBold(bool bold)
+{
+ QFont f(font());
+ f.setBold(bold);
+ setFont(f);
+}
diff --git a/sneakylineedit.h b/sneakylineedit.h
new file mode 100644
--- /dev/null
+++ b/sneakylineedit.h
@@ -0,0 +1,19 @@
+#ifndef SNEAKYLINEEDIT_H
+#define SNEAKYLINEEDIT_H
+
+#include
+#include
+
+class SneakyLineEdit : public QLineEdit
+{
+ Q_OBJECT
+public:
+ explicit SneakyLineEdit(QWidget *parent = 0);
+
+private:
+ void focusInEvent(QFocusEvent * event);
+ void focusOutEvent(QFocusEvent * event);
+ void setBold(bool bold);
+};
+
+#endif // SNEAKYLINEEDIT_H