Messagelib

statusbarlabeltoggledstate.cpp
1 /*
2  SPDX-FileCopyrightText: 2014-2022 Laurent Montel <[email protected]>
3 
4  SPDX-License-Identifier: GPL-2.0-or-later
5 */
6 
7 #include "statusbarlabeltoggledstate.h"
8 #include "messagecomposer_debug.h"
9 #include <QMouseEvent>
10 using namespace MessageComposer;
11 StatusBarLabelToggledState::StatusBarLabelToggledState(QWidget *parent)
12  : QLabel(parent)
13 {
14  setTextFormat(Qt::PlainText);
15 }
16 
17 StatusBarLabelToggledState::~StatusBarLabelToggledState() = default;
18 
19 void StatusBarLabelToggledState::setStateString(const QString &toggled, const QString &untoggled)
20 {
21  if (toggled.isEmpty() || untoggled.isEmpty()) {
22  qCWarning(MESSAGECOMPOSER_LOG) << " State string is empty. Need to fix it";
23  }
24  mToggled = toggled;
25  mUnToggled = untoggled;
26  updateLabel();
27 }
28 
29 void StatusBarLabelToggledState::setToggleMode(bool state)
30 {
31  if (mToggleMode != state) {
32  mToggleMode = state;
33  Q_EMIT toggleModeChanged(mToggleMode);
34  updateLabel();
35  }
36 }
37 
38 bool StatusBarLabelToggledState::toggleMode() const
39 {
40  return mToggleMode;
41 }
42 
43 void StatusBarLabelToggledState::updateLabel()
44 {
45  if (mToggleMode) {
46  setText(mToggled);
47  } else {
48  setText(mUnToggled);
49  }
50 }
51 
52 void StatusBarLabelToggledState::mousePressEvent(QMouseEvent *ev)
53 {
54  Q_UNUSED(ev)
55  if (ev->button() == Qt::LeftButton) {
56  setToggleMode(!mToggleMode);
57  }
58 }
PlainText
Simple interface that both EncryptJob and SignEncryptJob implement so the composer can extract some e...
Qt::MouseButton button() const const
LeftButton
bool isEmpty() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sat May 21 2022 03:53:37 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.