Changeset - cc65dd8fc5fc
[Not reviewed]
default
0 7 2
Hasan Yavuz Ă–ZDERYA - 10 years ago 2016-02-28 09:21:55
hy@ozderya.net
added command name widget
9 files changed with 83 insertions and 2 deletions:
0 comments (0 inline, 0 general)
CMakeLists.txt
Show inline comments
 
@@ -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
commandpanel.cpp
Show inline comments
 
@@ -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);
 
}
commandpanel.h
Show inline comments
 
@@ -42,6 +42,8 @@ private:
 
    Ui::CommandPanel *ui;
 
    QSerialPort* serialPort;
 

	
 
    unsigned command_name_counter;
 

	
 
private slots:
 
    void newCommand();
 
    void sendCommand(QByteArray command);
commandwidget.cpp
Show inline comments
 
@@ -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();
 
}
commandwidget.h
Show inline comments
 
@@ -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
 

	
commandwidget.ui
Show inline comments
 
@@ -48,6 +48,9 @@
 
    </widget>
 
   </item>
 
   <item>
 
    <widget class="SneakyLineEdit" name="leName"/>
 
   </item>
 
   <item>
 
    <widget class="CommandEdit" name="leCommand">
 
     <property name="sizePolicy">
 
      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
 
@@ -167,6 +170,11 @@
 
   <extends>QLineEdit</extends>
 
   <header>commandedit.h</header>
 
  </customwidget>
 
  <customwidget>
 
   <class>SneakyLineEdit</class>
 
   <extends>QLineEdit</extends>
 
   <header>sneakylineedit.h</header>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections/>
serialplot.pro
Show inline comments
 
@@ -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 \
sneakylineedit.cpp
Show inline comments
 
new file 100644
 
#include "sneakylineedit.h"
 
#include <QFont>
 

	
 
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);
 
}
sneakylineedit.h
Show inline comments
 
new file 100644
 
#ifndef SNEAKYLINEEDIT_H
 
#define SNEAKYLINEEDIT_H
 

	
 
#include <QLineEdit>
 
#include <QFocusEvent>
 

	
 
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
0 comments (0 inline, 0 general)