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
 
@@ -85,12 +85,13 @@ add_executable(${PROGRAM_NAME} WIN32
 
  plotsnapshotoverlay.cpp
 
  commandpanel.cpp
 
  commandwidget.cpp
 
  commandedit.cpp
 
  dataformatpanel.cpp
 
  tooltipfilter.cpp
 
  sneakylineedit.cpp
 
  ${UI_FILES}
 
  ${RES_FILES}
 
  misc/windows_icon.rc
 
  )
 

	
 
# Use the Widgets module from Qt 5.
commandpanel.cpp
Show inline comments
 
@@ -35,23 +35,26 @@ CommandPanel::CommandPanel(QSerialPort* 
 
#ifdef Q_OS_WIN
 
    ui->pbNew->setIcon(QIcon(":/icons/list-add"));
 
#endif // Q_OS_WIN
 

	
 
    connect(ui->pbNew, &QPushButton::clicked, this, &CommandPanel::newCommand);
 

	
 
    command_name_counter = 0;
 
    newCommand(); // add an empty slot by default
 
}
 

	
 
CommandPanel::~CommandPanel()
 
{
 
    delete ui;
 
}
 

	
 
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);
 
}
 

	
 
void CommandPanel::sendCommand(QByteArray command)
 
{
commandpanel.h
Show inline comments
 
@@ -39,12 +39,14 @@ public:
 
    ~CommandPanel();
 

	
 
private:
 
    Ui::CommandPanel *ui;
 
    QSerialPort* serialPort;
 

	
 
    unsigned command_name_counter;
 

	
 
private slots:
 
    void newCommand();
 
    void sendCommand(QByteArray command);
 
};
 

	
 
#endif // COMMANDPANEL_H
commandwidget.cpp
Show inline comments
 
@@ -90,6 +90,16 @@ void CommandWidget::onASCIIToggled(bool 
 
}
 

	
 
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
 
@@ -32,12 +32,15 @@ class CommandWidget : public QWidget
 
    Q_OBJECT
 

	
 
public:
 
    explicit CommandWidget(QWidget *parent = 0);
 
    ~CommandWidget();
 

	
 
    void setName(QString name);
 
    QString name();
 

	
 
signals:
 
    void deleteRequested(CommandWidget* thisWidget); // emitted when delete button is clicked
 

	
 
    // emitted when send button is clicked
 
    //
 
    // in case of hex mode, command text should be a hexadecimal
commandwidget.ui
Show inline comments
 
@@ -45,12 +45,15 @@
 
     <property name="autoRaise">
 
      <bool>true</bool>
 
     </property>
 
    </widget>
 
   </item>
 
   <item>
 
    <widget class="SneakyLineEdit" name="leName"/>
 
   </item>
 
   <item>
 
    <widget class="CommandEdit" name="leCommand">
 
     <property name="sizePolicy">
 
      <sizepolicy hsizetype="MinimumExpanding" vsizetype="Fixed">
 
       <horstretch>0</horstretch>
 
       <verstretch>0</verstretch>
 
      </sizepolicy>
 
@@ -164,10 +167,15 @@
 
 <customwidgets>
 
  <customwidget>
 
   <class>CommandEdit</class>
 
   <extends>QLineEdit</extends>
 
   <header>commandedit.h</header>
 
  </customwidget>
 
  <customwidget>
 
   <class>SneakyLineEdit</class>
 
   <extends>QLineEdit</extends>
 
   <header>sneakylineedit.h</header>
 
  </customwidget>
 
 </customwidgets>
 
 <resources/>
 
 <connections/>
 
</ui>
serialplot.pro
Show inline comments
 
@@ -48,13 +48,14 @@ SOURCES += main.cpp\
 
    snapshot.cpp \
 
    plotsnapshotoverlay.cpp \
 
    commandpanel.cpp \
 
    commandwidget.cpp \
 
    commandedit.cpp \
 
    dataformatpanel.cpp \
 
    tooltipfilter.cpp
 
    tooltipfilter.cpp \
 
    sneakylineedit.cpp
 

	
 
HEADERS  += mainwindow.h \
 
    utils.h \
 
    portcontrol.h \
 
    floatswap.h \
 
    plot.h \
 
@@ -69,13 +70,14 @@ HEADERS  += mainwindow.h \
 
    snapshot.h \
 
    plotsnapshotoverlay.h \
 
    commandpanel.h \
 
    commandwidget.h \
 
    commandedit.h \
 
    dataformatpanel.h \
 
    tooltipfilter.h
 
    tooltipfilter.h \
 
    sneakylineedit.h
 

	
 
FORMS    += mainwindow.ui \
 
    about_dialog.ui \
 
    portcontrol.ui \
 
    snapshotview.ui \
 
    commandpanel.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)