Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
PIM
Kleopatra
Commits
c7c45ac3
Commit
c7c45ac3
authored
Aug 15, 2022
by
Ingo Klöcker
Browse files
Make InfoField available for other parts of Kleopatra
GnuPG-bug-id: 6046
parent
7bfd7829
Changes
4
Hide whitespace changes
Inline
Side-by-side
src/CMakeLists.txt
View file @
c7c45ac3
...
...
@@ -477,6 +477,8 @@ set(_kleopatra_SRCS
view/formtextinput.h
view/htmllabel.cpp
view/htmllabel.h
view/infofield.cpp
view/infofield.h
view/keycacheoverlay.cpp
view/keycacheoverlay.h
view/keylistcontroller.cpp
...
...
src/dialogs/certificatedetailswidget.cpp
View file @
c7c45ac3
...
...
@@ -38,6 +38,7 @@
#include
"utils/accessibility.h"
#include
"utils/keys.h"
#include
"utils/tags.h"
#include
"view/infofield.h"
#include
<Libkleo/Algorithm>
#include
<Libkleo/Compliance>
...
...
@@ -85,130 +86,6 @@ Q_DECLARE_METATYPE(GpgME::UserID)
using
namespace
Kleo
;
class
InfoField
{
public:
InfoField
(
const
QString
&
label
,
QWidget
*
parent
);
void
setValue
(
const
QString
&
value
,
const
QString
&
accessibleValue
=
{});
QString
value
()
const
;
void
setIcon
(
const
QIcon
&
icon
);
void
setAction
(
const
QAction
*
action
);
void
setToolTip
(
const
QString
&
toolTip
);
void
setVisible
(
bool
visible
);
QLabel
*
label
()
const
{
return
mLabel
;
}
QLayout
*
layout
()
const
{
return
mLayout
;
}
private:
void
onActionChanged
();
QLabel
*
mLabel
=
nullptr
;
QHBoxLayout
*
mLayout
=
nullptr
;
QLabel
*
mIcon
=
nullptr
;
QLabel
*
mValue
=
nullptr
;
QPushButton
*
mButton
=
nullptr
;
const
QAction
*
mAction
=
nullptr
;
};
InfoField
::
InfoField
(
const
QString
&
label
,
QWidget
*
parent
)
:
mLabel
{
new
QLabel
{
label
,
parent
}}
,
mLayout
{
new
QHBoxLayout
}
,
mIcon
{
new
QLabel
{
parent
}}
,
mValue
{
new
QLabel
{
parent
}}
,
mButton
{
new
QPushButton
{
parent
}}
{
mLabel
->
setBuddy
(
mValue
);
mLabel
->
setTextInteractionFlags
(
Qt
::
TextSelectableByMouse
);
mIcon
->
setVisible
(
false
);
mLayout
->
addWidget
(
mIcon
);
mValue
->
setTextInteractionFlags
(
Qt
::
TextSelectableByMouse
);
mValue
->
setFocusPolicy
(
Qt
::
TabFocus
);
mLayout
->
addWidget
(
mValue
);
mButton
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
);
mButton
->
setVisible
(
false
);
mLayout
->
addWidget
(
mButton
);
mLayout
->
addStretch
();
}
void
InfoField
::
setValue
(
const
QString
&
value
,
const
QString
&
accessibleValue
)
{
mValue
->
setText
(
value
);
mValue
->
setAccessibleName
(
accessibleValue
);
}
QString
InfoField
::
value
()
const
{
return
mValue
->
text
();
}
void
InfoField
::
setIcon
(
const
QIcon
&
icon
)
{
if
(
!
icon
.
isNull
())
{
const
int
iconSize
=
mIcon
->
style
()
->
pixelMetric
(
QStyle
::
PM_SmallIconSize
,
nullptr
,
mIcon
);
mIcon
->
setPixmap
(
icon
.
pixmap
(
iconSize
));
mIcon
->
setVisible
(
true
);
}
else
{
mIcon
->
setVisible
(
false
);
mIcon
->
clear
();
}
}
void
InfoField
::
setAction
(
const
QAction
*
action
)
{
if
(
action
==
mAction
)
{
return
;
}
if
(
mAction
)
{
QObject
::
disconnect
(
mButton
,
{},
mAction
,
{});
QObject
::
disconnect
(
mAction
,
{},
mButton
,
{});
}
mAction
=
action
;
if
(
mAction
)
{
QObject
::
connect
(
mButton
,
&
QPushButton
::
clicked
,
action
,
&
QAction
::
trigger
);
QObject
::
connect
(
mAction
,
&
QAction
::
changed
,
mButton
,
[
this
]()
{
onActionChanged
();
});
onActionChanged
();
mButton
->
setAccessibleName
(
getAccessibleName
(
mAction
));
mButton
->
setVisible
(
true
);
}
else
{
mButton
->
setVisible
(
false
);
mButton
->
setText
({});
mButton
->
setIcon
({});
}
}
void
InfoField
::
setToolTip
(
const
QString
&
toolTip
)
{
mValue
->
setToolTip
(
toolTip
);
}
void
InfoField
::
setVisible
(
bool
visible
)
{
mLabel
->
setVisible
(
visible
);
mIcon
->
setVisible
(
visible
&&
!
mIcon
->
pixmap
(
Qt
::
ReturnByValue
).
isNull
());
mValue
->
setVisible
(
visible
);
mButton
->
setVisible
(
visible
&&
mAction
);
}
void
InfoField
::
onActionChanged
()
{
if
(
!
mAction
)
{
return
;
}
if
(
mAction
->
text
()
!=
mButton
->
text
())
{
mButton
->
setText
(
mAction
->
text
());
}
mButton
->
setIcon
(
mAction
->
icon
());
if
(
mAction
->
toolTip
()
!=
mButton
->
toolTip
())
{
mButton
->
setToolTip
(
mAction
->
toolTip
());
}
if
(
mAction
->
isEnabled
()
!=
mButton
->
isEnabled
())
{
mButton
->
setEnabled
(
mAction
->
isEnabled
());
}
}
namespace
{
std
::
vector
<
GpgME
::
UserID
>
selectedUserIDs
(
const
QTreeWidget
*
treeWidget
)
{
...
...
src/view/infofield.cpp
0 → 100644
View file @
c7c45ac3
/* view/infofield.cpp
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#include
<config-kleopatra.h>
#include
"infofield.h"
#include
"utils/accessibility.h"
#include
<QAction>
#include
<QHBoxLayout>
#include
<QIcon>
#include
<QLabel>
#include
<QLayout>
#include
<QPushButton>
#include
<QStyle>
using
namespace
Kleo
;
InfoField
::
InfoField
(
const
QString
&
label
,
QWidget
*
parent
)
:
mLabel
{
new
QLabel
{
label
,
parent
}}
,
mLayout
{
new
QHBoxLayout
}
,
mIcon
{
new
QLabel
{
parent
}}
,
mValue
{
new
QLabel
{
parent
}}
,
mButton
{
new
QPushButton
{
parent
}}
{
mLabel
->
setBuddy
(
mValue
);
mLabel
->
setTextInteractionFlags
(
Qt
::
TextSelectableByMouse
);
mIcon
->
setVisible
(
false
);
mLayout
->
addWidget
(
mIcon
);
mValue
->
setTextInteractionFlags
(
Qt
::
TextSelectableByMouse
);
mValue
->
setFocusPolicy
(
Qt
::
TabFocus
);
mLayout
->
addWidget
(
mValue
);
mButton
->
setSizePolicy
(
QSizePolicy
::
Fixed
,
QSizePolicy
::
Fixed
);
mButton
->
setVisible
(
false
);
mLayout
->
addWidget
(
mButton
);
mLayout
->
addStretch
();
}
QLabel
*
InfoField
::
label
()
const
{
return
mLabel
;
}
QLayout
*
InfoField
::
layout
()
const
{
return
mLayout
;
}
void
InfoField
::
setValue
(
const
QString
&
value
,
const
QString
&
accessibleValue
)
{
mValue
->
setText
(
value
);
mValue
->
setAccessibleName
(
accessibleValue
);
}
QString
InfoField
::
value
()
const
{
return
mValue
->
text
();
}
void
InfoField
::
setIcon
(
const
QIcon
&
icon
)
{
if
(
!
icon
.
isNull
())
{
const
int
iconSize
=
mIcon
->
style
()
->
pixelMetric
(
QStyle
::
PM_SmallIconSize
,
nullptr
,
mIcon
);
mIcon
->
setPixmap
(
icon
.
pixmap
(
iconSize
));
mIcon
->
setVisible
(
true
);
}
else
{
mIcon
->
setVisible
(
false
);
mIcon
->
clear
();
}
}
void
InfoField
::
setAction
(
const
QAction
*
action
)
{
if
(
action
==
mAction
)
{
return
;
}
if
(
mAction
)
{
QObject
::
disconnect
(
mButton
,
{},
mAction
,
{});
QObject
::
disconnect
(
mAction
,
{},
mButton
,
{});
}
mAction
=
action
;
if
(
mAction
)
{
QObject
::
connect
(
mButton
,
&
QPushButton
::
clicked
,
action
,
&
QAction
::
trigger
);
QObject
::
connect
(
mAction
,
&
QAction
::
changed
,
mButton
,
[
this
]()
{
onActionChanged
();
});
onActionChanged
();
mButton
->
setAccessibleName
(
getAccessibleName
(
mAction
));
mButton
->
setVisible
(
true
);
}
else
{
mButton
->
setVisible
(
false
);
mButton
->
setText
({});
mButton
->
setIcon
({});
}
}
void
InfoField
::
setToolTip
(
const
QString
&
toolTip
)
{
mValue
->
setToolTip
(
toolTip
);
}
void
InfoField
::
setVisible
(
bool
visible
)
{
mLabel
->
setVisible
(
visible
);
mIcon
->
setVisible
(
visible
&&
!
mIcon
->
pixmap
(
Qt
::
ReturnByValue
).
isNull
());
mValue
->
setVisible
(
visible
);
mButton
->
setVisible
(
visible
&&
mAction
);
}
void
InfoField
::
onActionChanged
()
{
if
(
!
mAction
)
{
return
;
}
if
(
mAction
->
text
()
!=
mButton
->
text
())
{
mButton
->
setText
(
mAction
->
text
());
}
mButton
->
setIcon
(
mAction
->
icon
());
if
(
mAction
->
toolTip
()
!=
mButton
->
toolTip
())
{
mButton
->
setToolTip
(
mAction
->
toolTip
());
}
if
(
mAction
->
isEnabled
()
!=
mButton
->
isEnabled
())
{
mButton
->
setEnabled
(
mAction
->
isEnabled
());
}
}
src/view/infofield.h
0 → 100644
View file @
c7c45ac3
/* view/infofield.h
This file is part of Kleopatra, the KDE keymanager
SPDX-FileCopyrightText: 2022 g10 Code GmbH
SPDX-FileContributor: Ingo Klöcker <dev@ingo-kloecker.de>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include
<QString>
class
QAction
;
class
QHBoxLayout
;
class
QIcon
;
class
QLabel
;
class
QLayout
;
class
QPushButton
;
class
QWidget
;
namespace
Kleo
{
class
InfoField
{
public:
InfoField
(
const
QString
&
label
,
QWidget
*
parent
);
QLabel
*
label
()
const
;
QLayout
*
layout
()
const
;
void
setValue
(
const
QString
&
value
,
const
QString
&
accessibleValue
=
{});
QString
value
()
const
;
void
setIcon
(
const
QIcon
&
icon
);
void
setAction
(
const
QAction
*
action
);
void
setToolTip
(
const
QString
&
toolTip
);
void
setVisible
(
bool
visible
);
private:
void
onActionChanged
();
QLabel
*
mLabel
=
nullptr
;
QHBoxLayout
*
mLayout
=
nullptr
;
QLabel
*
mIcon
=
nullptr
;
QLabel
*
mValue
=
nullptr
;
QPushButton
*
mButton
=
nullptr
;
const
QAction
*
mAction
=
nullptr
;
};
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment