Saving history of line edit for command line ("dot commands")

This commit is contained in:
Klaus Basan
2017-01-28 18:43:49 +01:00
committed by Mathew Sutcliffe
parent 1967c82221
commit 5b3780543f
5 changed files with 312 additions and 199 deletions

View File

@@ -31,7 +31,6 @@ namespace BlackGui
{ {
namespace Components namespace Components
{ {
CMainKeypadAreaComponent::CMainKeypadAreaComponent(QWidget *parent) : CMainKeypadAreaComponent::CMainKeypadAreaComponent(QWidget *parent) :
QFrame(parent), QFrame(parent),
ui(new Ui::CMainKeypadAreaComponent) ui(new Ui::CMainKeypadAreaComponent)
@@ -62,7 +61,7 @@ namespace BlackGui
connect(ui->pb_SoundMute, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected); connect(ui->pb_SoundMute, &QPushButton::released, this, &CMainKeypadAreaComponent::ps_buttonSelected);
// command line // command line
this->connect(ui->le_CommandLineInput, &QLineEdit::returnPressed, this, &CMainKeypadAreaComponent::ps_commandEntered); this->connect(ui->lep_CommandLineInput, &QLineEdit::returnPressed, this, &CMainKeypadAreaComponent::ps_commandEntered);
connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged); connect(sGui->getIContextNetwork(), &IContextNetwork::connectionStatusChanged, this, &CMainKeypadAreaComponent::ps_connectionStatusChanged);
connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged); connect(sGui->getIContextOwnAircraft(), &IContextOwnAircraft::changedAircraftCockpit, this, &CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged);
@@ -154,10 +153,9 @@ namespace BlackGui
void CMainKeypadAreaComponent::ps_commandEntered() void CMainKeypadAreaComponent::ps_commandEntered()
{ {
QString c(ui->le_CommandLineInput->text().trimmed().simplified()); QString c(ui->lep_CommandLineInput->getLastEnteredLineFormatted());
if (c.isEmpty()) { return; } if (c.isEmpty()) { return; }
emit this->commandEntered(c, keypadIdentifier()); emit this->commandEntered(c, keypadIdentifier());
ui->le_CommandLineInput->clear();
} }
void CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged(const CSimulatedAircraft &aircraft, const CIdentifier &originator) void CMainKeypadAreaComponent::ps_ownAircraftCockpitChanged(const CSimulatedAircraft &aircraft, const CIdentifier &originator)

View File

@@ -7,7 +7,7 @@
<x>0</x> <x>0</x>
<y>0</y> <y>0</y>
<width>410</width> <width>410</width>
<height>120</height> <height>122</height>
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
@@ -62,13 +62,143 @@
<property name="spacing"> <property name="spacing">
<number>2</number> <number>2</number>
</property> </property>
<item row="0" column="0" colspan="5"> <item row="2" column="3">
<widget class="QLineEdit" name="le_CommandLineInput"> <widget class="QPushButton" name="pb_Empty_2">
<property name="toolTip"> <property name="enabled">
<string>command line (e.g. &quot;.com1&quot;, &quot;.x&quot;, &quot;.msg com1&quot;)</string> <bool>false</bool>
</property> </property>
<property name="placeholderText"> <property name="text">
<string>.dot commands or text message</string> <string/>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pb_MainFlightplan">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Flightplan</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QPushButton" name="pb_MainLog">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Log</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="pb_Empty_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="pb_Empty">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="pb_MainMappings">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Rendering</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pb_MainCockpit">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Cockpit</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pb_MainTextMessages">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Text/Chat</string>
</property>
<property name="checkable">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@@ -138,8 +268,20 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="0"> <item row="4" column="3">
<widget class="QPushButton" name="pb_MainUsers"> <widget class="QPushButton" name="pb_Opacity100">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>62</width>
<height>22</height>
</size>
</property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
@@ -147,26 +289,7 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>Users</string> <string>100%</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="pb_MainSimulator">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Simulator</string>
</property>
<property name="checkable">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@@ -192,20 +315,8 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="4" column="3"> <item row="2" column="1">
<widget class="QPushButton" name="pb_Opacity100"> <widget class="QPushButton" name="pb_MainSimulator">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>62</width>
<height>22</height>
</size>
</property>
<property name="maximumSize"> <property name="maximumSize">
<size> <size>
<width>16777215</width> <width>16777215</width>
@@ -213,7 +324,42 @@
</size> </size>
</property> </property>
<property name="text"> <property name="text">
<string>100%</string> <string>Simulator</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QPushButton" name="pb_MainUsers">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Users</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="4">
<widget class="QPushButton" name="pb_CockpitIdent">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Ident</string>
</property>
<property name="checkable">
<bool>true</bool>
</property> </property>
</widget> </widget>
</item> </item>
@@ -274,66 +420,6 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="1" column="4">
<widget class="QPushButton" name="pb_CockpitIdent">
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Ident</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QPushButton" name="pb_MainTextMessages">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Text/Chat</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="pb_MainCockpit">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Cockpit</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="2"> <item row="4" column="2">
<widget class="QPushButton" name="pb_MainSettings"> <widget class="QPushButton" name="pb_MainSettings">
<property name="sizePolicy"> <property name="sizePolicy">
@@ -359,99 +445,19 @@
</property> </property>
</widget> </widget>
</item> </item>
<item row="3" column="2"> <item row="0" column="0" colspan="5">
<widget class="QPushButton" name="pb_MainLog"> <widget class="BlackGui::CLineEditHistory" name="lep_CommandLineInput">
<property name="sizePolicy"> <property name="minimumSize">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size> <size>
<width>16777215</width> <width>0</width>
<height>16777215</height> <height>24</height>
</size> </size>
</property> </property>
<property name="text"> <property name="toolTip">
<string>Log</string> <string>command line (e.g. &quot;.com1&quot;, &quot;.x&quot;, &quot;.msg com1&quot;)</string>
</property> </property>
<property name="checkable"> <property name="placeholderText">
<bool>true</bool> <string>.dot commands or text message</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QPushButton" name="pb_MainFlightplan">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Flightplan</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="pb_MainMappings">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="maximumSize">
<size>
<width>16777215</width>
<height>16777215</height>
</size>
</property>
<property name="text">
<string>Rendering</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
</widget>
</item>
<item row="2" column="3">
<widget class="QPushButton" name="pb_Empty_2">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QPushButton" name="pb_Empty">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="4">
<widget class="QPushButton" name="pb_Empty_3">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string/>
</property> </property>
</widget> </widget>
</item> </item>
@@ -460,8 +466,15 @@
</item> </item>
</layout> </layout>
</widget> </widget>
<customwidgets>
<customwidget>
<class>BlackGui::CLineEditHistory</class>
<extends>QLineEdit</extends>
<header>blackgui/lineedithistory.h</header>
</customwidget>
</customwidgets>
<tabstops> <tabstops>
<tabstop>le_CommandLineInput</tabstop> <tabstop>lep_CommandLineInput</tabstop>
<tabstop>pb_Connect</tabstop> <tabstop>pb_Connect</tabstop>
<tabstop>pb_MainAircrafts</tabstop> <tabstop>pb_MainAircrafts</tabstop>
<tabstop>pb_MainAtc</tabstop> <tabstop>pb_MainAtc</tabstop>

View File

@@ -0,0 +1,58 @@
/* Copyright (C) 2017
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
#include "lineedithistory.h"
#include <QKeyEvent>
namespace BlackGui
{
QString CLineEditHistory::getLastEnteredLine() const
{
if (m_history.isEmpty()) return {};
return m_history.first();
}
QString CLineEditHistory::getLastEnteredLineFormatted() const
{
return getLastEnteredLine().trimmed().simplified();
}
void CLineEditHistory::keyPressEvent(QKeyEvent *event)
{
if (event->key() == Qt::Key_Up)
{
// move back in history
if (m_history.size() > m_position)
{
setText(m_history.at(m_position++));
}
}
else if (event->key() == Qt::Key_Down)
{
// move forward in history
if (m_position <= 0) { clear(); return; }
if (m_position == m_history.size()) { --m_position; } // avoid need of 2xKeyDown at end
if (m_position > 0 && m_history.size() > --m_position)
{
setText(m_history.at(m_position));
}
}
else if (event->key() == Qt::Key_Return)
{
if (!text().isEmpty())
{
m_history.push_front(text());
m_position = 0;
clear();
}
}
// default handler for event
QLineEdit::keyPressEvent(event);
}
} // ns

View File

@@ -0,0 +1,44 @@
/* Copyright (C) 2017
* swift project Community / Contributors
*
* This file is part of swift Project. It is subject to the license terms in the LICENSE file found in the top-level
* directory of this distribution and at http://www.swift-project.org/license.html. No part of swift project,
* including this file, may be copied, modified, propagated, or distributed except according to the terms
* contained in the LICENSE file.
*/
//! \file
#ifndef BLACKGUI_LINEEDITHISTORY_H
#define BLACKGUI_LINEEDITHISTORY_H
#include <QLineEdit>
#include <QStringList>
namespace BlackGui
{
/*!
* Line edit with history
*/
class CLineEditHistory : public QLineEdit
{
public:
//! Constructors
using QLineEdit::QLineEdit;
//! Get the last entered line
QString getLastEnteredLine() const;
//! Get the last entered line but simplified and trimmed
QString getLastEnteredLineFormatted() const;
protected:
//! \copydoc QLineEdit::keyPressEvent
virtual void keyPressEvent(QKeyEvent *event) override;
private:
QStringList m_history;
int m_position = 0;
};
} // ns
#endif // guard

View File

@@ -240,7 +240,7 @@ QLabel {
} }
QLineEdit { QLineEdit {
background: transparent; background: black;
border: 1px solid green; border: 1px solid green;
border-radius: 5px; border-radius: 5px;
} }