aboutsummaryrefslogtreecommitdiff
path: root/src/WindowNotification.cpp
blob: 9e1710805ec427e059c1eb611e05a2d2309c6944 (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
#include "../include/WindowNotification.hpp"
#include <gtkmm.h>

namespace dchat
{
    WindowNotification::WindowNotification()
    {
        label.set_line_wrap(true);
        label.set_line_wrap_mode(Pango::WRAP_WORD_CHAR);
        label.set_halign(Gtk::ALIGN_CENTER);
        revealer.add(label);
        revealer.set_hexpand(true);

        Gtk::Grid *grid = Gtk::manage(new Gtk::Grid());
        grid->add(revealer);
        grid->get_style_context()->add_class("window-notification");

        add(*grid);
        set_valign(Gtk::ALIGN_START);
        set_hexpand(true);
        show_all();
        set_visible(false);
    }

    void WindowNotification::show(const Glib::ustring &text)
    {
        hideTimer.disconnect();
        visibilityTimer.disconnect();
        label.set_text(text);
        set_visible(true);
        revealer.set_reveal_child(true);
        int showTime = (int)std::max(1.0, (double)text.size() * 0.1) * 1000;

        hideTimer = Glib::signal_timeout().connect([this]
        {
            revealer.set_reveal_child(false);
            return false;
        }, showTime);

        visibilityTimer = Glib::signal_timeout().connect([this]
        {
            set_visible(false);
            return false;
        }, showTime + revealer.get_transition_duration());
    }
}