summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/canvas-notice.cpp
blob: 0337bf94b8f28f426c7a86324f83cfbfdc5500c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
// SPDX-License-Identifier: GPL-2.0-or-later

#include "canvas-notice.h"

#include <utility>
#include <glibmm/main.h>

#include "ui/builder-utils.h"

namespace Inkscape {
namespace UI {
namespace Widget {


CanvasNotice::CanvasNotice(BaseObjectType *cobject, Glib::RefPtr<Gtk::Builder> builder)
    : Gtk::Revealer(cobject)
    , _builder(std::move(builder))
    , _icon(get_widget<Gtk::Image>(_builder, "notice-icon"))
    , _label(get_widget<Gtk::Label>(_builder, "notice-label"))
{
    auto &close = get_widget<Gtk::Button>(_builder, "notice-close");
    close.signal_clicked().connect([=]() {
        hide();
    });
}

void CanvasNotice::show(Glib::ustring const &msg, unsigned timeout)
{
    _label.set_text(msg);
    set_reveal_child(true);
    if (timeout != 0) {
        _timeout = Glib::signal_timeout().connect([=]() {
            hide();
            return false;
        }, timeout);
    }
}

void CanvasNotice::hide()
{
    set_reveal_child(false);
}

CanvasNotice *CanvasNotice::create()
{
    CanvasNotice *widget = nullptr;
    auto builder = create_builder("canvas-notice.glade");
    builder->get_widget_derived("canvas-notice", widget);
    return widget;
}

}}} // namespaces