keepassxc

Форк
0
/
MessageWidget.cpp 
106 строк · 2.8 Кб
1
/*
2
 *  Copyright (C) 2015 Pedro Alves <devel@pgalves.com>
3
 *  Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation, either version 2 or (at your option)
8
 *  version 3 of the License.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU General Public License
16
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18

19
#include "MessageWidget.h"
20

21
#include <QDesktopServices>
22
#include <QTimer>
23
#include <QUrl>
24

25
const int MessageWidget::DefaultAutoHideTimeout = 6000;
26
const int MessageWidget::LongAutoHideTimeout = 15000;
27
const int MessageWidget::DisableAutoHide = -1;
28

29
MessageWidget::MessageWidget(QWidget* parent)
30
    : KMessageWidget(parent)
31
    , m_autoHideTimer(new QTimer(this))
32
    , m_autoHideTimeout(DefaultAutoHideTimeout)
33
{
34
    m_autoHideTimer->setSingleShot(true);
35
    connect(m_autoHideTimer, SIGNAL(timeout()), this, SLOT(animatedHide()));
36
    connect(this, SIGNAL(hideAnimationFinished()), m_autoHideTimer, SLOT(stop()));
37
}
38

39
void MessageWidget::setAnimate(bool state)
40
{
41
    m_animate = state;
42
}
43

44
int MessageWidget::autoHideTimeout() const
45
{
46
    return m_autoHideTimeout;
47
}
48

49
void MessageWidget::showMessage(const QString& text, MessageWidget::MessageType type)
50
{
51
    showMessage(text, type, m_autoHideTimeout);
52
}
53

54
void MessageWidget::showMessage(const QString& text, KMessageWidget::MessageType type, int autoHideTimeout)
55
{
56
    setMessageType(type);
57
    setText(text);
58

59
    emit showAnimationStarted();
60
    if (m_animate) {
61
        animatedShow();
62
    } else {
63
        show();
64
        emit showAnimationFinished();
65
    }
66

67
    if (autoHideTimeout > 0) {
68
        m_autoHideTimer->start(autoHideTimeout);
69
    } else {
70
        m_autoHideTimer->stop();
71
    }
72
}
73

74
void MessageWidget::hideMessage()
75
{
76
    emit hideAnimationStarted();
77
    if (m_animate) {
78
        animatedHide();
79
    } else {
80
        hide();
81
        emit hideAnimationFinished();
82
    }
83

84
    m_autoHideTimer->stop();
85
}
86

87
void MessageWidget::setAutoHideTimeout(int autoHideTimeout)
88
{
89
    m_autoHideTimeout = autoHideTimeout;
90
    if (autoHideTimeout <= 0) {
91
        m_autoHideTimer->stop();
92
    }
93
}
94

95
/**
96
 * Open a link using the system's default handler.
97
 * Links that are not HTTP(S) links are ignored.
98
 *
99
 * @param link link URL
100
 */
101
void MessageWidget::openHttpUrl(const QString& link)
102
{
103
    if (link.startsWith("http://") || link.startsWith("https://")) {
104
        QDesktopServices::openUrl(QUrl(link));
105
    }
106
}
107

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.