gui: Don't use friends to limit access to Action

This commit is contained in:
Povilas Kanapickas 2021-01-10 13:39:38 +02:00
parent 0579101272
commit 68cfb4e585
3 changed files with 26 additions and 23 deletions

View File

@ -51,7 +51,7 @@ QString Action::text() const
* in the end but now argument inside. If you need a function with no
* argument, it can not have () in the end.
*/
QString text = QString(m_ActionTypeNames[keySequence().isMouseButton() ?
QString text = QString(m_ActionTypeNames[m_KeySequence.isMouseButton() ?
type() + int(mouseDown) : type()]);
switch (type())
@ -61,9 +61,9 @@ QString Action::text() const
case keystroke:
{
text += "(";
text += keySequence().toString();
text += m_KeySequence.toString();
if (!keySequence().isMouseButton())
if (!m_KeySequence.isMouseButton())
{
const QStringList& screens = typeScreenNames();
if (haveScreens() && !screens.isEmpty())
@ -116,15 +116,15 @@ QString Action::text() const
void Action::loadSettings(QSettings& settings)
{
keySequence().loadSettings(settings);
m_KeySequence.loadSettings(settings);
setType(settings.value("type", keyDown).toInt());
typeScreenNames().clear();
m_TypeScreenNames.clear();
int numTypeScreens = settings.beginReadArray("typeScreenNames");
for (int i = 0; i < numTypeScreens; i++)
{
settings.setArrayIndex(i);
typeScreenNames().append(settings.value("typeScreenName").toString());
m_TypeScreenNames.append(settings.value("typeScreenName").toString());
}
settings.endArray();
@ -137,7 +137,7 @@ void Action::loadSettings(QSettings& settings)
void Action::saveSettings(QSettings& settings) const
{
keySequence().saveSettings(settings);
m_KeySequence.saveSettings(settings);
settings.setValue("type", type());
settings.beginWriteArray("typeScreenNames");

View File

@ -32,9 +32,6 @@ class QTextStream;
class Action
{
friend class ActionDialog;
friend QTextStream& operator<<(QTextStream& outStream, const Action& action);
public:
enum ActionType { keyDown, keyUp, keystroke,
switchToScreen, toggleScreen, switchInDirection,
@ -48,25 +45,31 @@ class Action
public:
QString text() const;
const KeySequence& keySequence() const { return m_KeySequence; }
void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; }
void loadSettings(QSettings& settings);
void saveSettings(QSettings& settings) const;
int type() const { return m_Type; }
const QStringList& typeScreenNames() const { return m_TypeScreenNames; }
const QString& switchScreenName() const { return m_SwitchScreenName; }
int switchDirection() const { return m_SwitchDirection; }
int lockCursorMode() const { return m_LockCursorMode; }
bool activeOnRelease() const { return m_ActiveOnRelease; }
bool haveScreens() const { return m_HasScreens; }
protected:
KeySequence& keySequence() { return m_KeySequence; }
void setKeySequence(const KeySequence& seq) { m_KeySequence = seq; }
int type() const { return m_Type; }
void setType(int t) { m_Type = t; }
QStringList& typeScreenNames() { return m_TypeScreenNames; }
const QStringList& typeScreenNames() const { return m_TypeScreenNames; }
void appendTypeScreenName(QString name) { m_TypeScreenNames.append(name); }
void clearTypeScreenNames() { m_TypeScreenNames.clear(); }
const QString& switchScreenName() const { return m_SwitchScreenName; }
void setSwitchScreenName(const QString& n) { m_SwitchScreenName = n; }
int switchDirection() const { return m_SwitchDirection; }
void setSwitchDirection(int d) { m_SwitchDirection = d; }
int lockCursorMode() const { return m_LockCursorMode; }
void setLockCursorMode(int m) { m_LockCursorMode = m; }
bool activeOnRelease() const { return m_ActiveOnRelease; }
void setActiveOnRelease(bool b) { m_ActiveOnRelease = b; }
bool haveScreens() const { return m_HasScreens; }
void setHaveScreens(bool b) { m_HasScreens = b; }
private:

View File

@ -83,9 +83,9 @@ void ActionDialog::accept()
m_Action.setType(m_pButtonGroupType->checkedId());
m_Action.setHaveScreens(m_pGroupBoxScreens->isChecked());
m_Action.typeScreenNames().clear();
m_Action.clearTypeScreenNames();
foreach(const QListWidgetItem* pItem, m_pListScreens->selectedItems())
m_Action.typeScreenNames().append(pItem->text());
m_Action.appendTypeScreenName(pItem->text());
m_Action.setSwitchScreenName(m_pComboSwitchToScreen->currentText());
m_Action.setSwitchDirection(m_pComboSwitchInDirection->currentIndex());