[Summary] Changed class PersistentTooltip. Now it can be used for 'non-draggable' tooltips.
[Feature reviewed] MKosharnyy [Reviewed] VKamyshniy Manually clean up merge mess, indentation, logic weakness, initializer order, etc. Conflicts: libs/gtkmm2ext/gtkmm2ext/persistent_tooltip.h libs/gtkmm2ext/persistent_tooltip.cc
This commit is contained in:
parent
a81bfbfc41
commit
f3719922c8
@ -31,15 +31,17 @@ namespace Gtkmm2ext {
|
|||||||
*/
|
*/
|
||||||
class LIBGTKMM2EXT_API PersistentTooltip : public sigc::trackable
|
class LIBGTKMM2EXT_API PersistentTooltip : public sigc::trackable
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PersistentTooltip (Gtk::Widget *, int margin_y = 0);
|
PersistentTooltip (Gtk::Widget *, bool draggable = false);
|
||||||
virtual ~PersistentTooltip ();
|
virtual ~PersistentTooltip ();
|
||||||
|
|
||||||
void set_tip (std::string);
|
void set_tip (std::string);
|
||||||
|
void set_font (Pango::FontDescription font);
|
||||||
|
void set_center_alignment (bool align_to_center);
|
||||||
|
|
||||||
virtual bool dragging () const;
|
virtual bool dragging () const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool timeout ();
|
bool timeout ();
|
||||||
void show ();
|
void show ();
|
||||||
void hide ();
|
void hide ();
|
||||||
@ -54,6 +56,10 @@ private:
|
|||||||
Gtk::Window* _window;
|
Gtk::Window* _window;
|
||||||
/** Our label */
|
/** Our label */
|
||||||
Gtk::Label* _label;
|
Gtk::Label* _label;
|
||||||
|
|
||||||
|
/** allow to drag
|
||||||
|
*/
|
||||||
|
bool _draggable;
|
||||||
/** true if we are `dragging', in the sense that button 1
|
/** true if we are `dragging', in the sense that button 1
|
||||||
is being held over _target.
|
is being held over _target.
|
||||||
*/
|
*/
|
||||||
@ -62,7 +68,8 @@ private:
|
|||||||
sigc::connection _timeout;
|
sigc::connection _timeout;
|
||||||
/** The tip text */
|
/** The tip text */
|
||||||
std::string _tip;
|
std::string _tip;
|
||||||
int _margin_y;
|
Pango::FontDescription _font;
|
||||||
|
bool _align_to_center;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -30,12 +30,13 @@ using namespace Gtk;
|
|||||||
using namespace Gtkmm2ext;
|
using namespace Gtkmm2ext;
|
||||||
|
|
||||||
/** @param target The widget to provide the tooltip for */
|
/** @param target The widget to provide the tooltip for */
|
||||||
PersistentTooltip::PersistentTooltip (Gtk::Widget* target, int margin_y)
|
PersistentTooltip::PersistentTooltip (Gtk::Widget* target, bool draggable)
|
||||||
: _target (target)
|
: _target (target)
|
||||||
, _window (0)
|
, _window (0)
|
||||||
, _label (0)
|
, _label (0)
|
||||||
|
, _draggable (draggable)
|
||||||
, _maybe_dragging (false)
|
, _maybe_dragging (false)
|
||||||
, _margin_y (margin_y)
|
, _align_to_center (true)
|
||||||
{
|
{
|
||||||
target->signal_enter_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::enter), false);
|
target->signal_enter_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::enter), false);
|
||||||
target->signal_leave_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::leave), false);
|
target->signal_leave_notify_event().connect (sigc::mem_fun (*this, &PersistentTooltip::leave), false);
|
||||||
@ -99,7 +100,7 @@ PersistentTooltip::release (GdkEventButton* ev)
|
|||||||
bool
|
bool
|
||||||
PersistentTooltip::dragging () const
|
PersistentTooltip::dragging () const
|
||||||
{
|
{
|
||||||
return _maybe_dragging;
|
return _maybe_dragging && _draggable;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -124,6 +125,7 @@ PersistentTooltip::show ()
|
|||||||
_window->set_decorated (false);
|
_window->set_decorated (false);
|
||||||
|
|
||||||
_label = manage (new Label);
|
_label = manage (new Label);
|
||||||
|
_label->modify_font (_font);
|
||||||
_label->set_use_markup (true);
|
_label->set_use_markup (true);
|
||||||
|
|
||||||
_window->set_border_width (6);
|
_window->set_border_width (6);
|
||||||
@ -140,7 +142,7 @@ PersistentTooltip::show ()
|
|||||||
|
|
||||||
if (!_window->is_visible ()) {
|
if (!_window->is_visible ()) {
|
||||||
int rx, ry;
|
int rx, ry;
|
||||||
int sw = gdk_screen_width();
|
int sw = gdk_screen_width ();
|
||||||
|
|
||||||
_target->get_window()->get_origin (rx, ry);
|
_target->get_window()->get_origin (rx, ry);
|
||||||
|
|
||||||
@ -151,10 +153,17 @@ PersistentTooltip::show ()
|
|||||||
_window->present ();
|
_window->present ();
|
||||||
|
|
||||||
if (sw < rx + _window->get_width()) {
|
if (sw < rx + _window->get_width()) {
|
||||||
|
/* right edge of window would be off the right edge of
|
||||||
|
the screen, so don't show it in the usual place.
|
||||||
|
*/
|
||||||
rx = sw - _window->get_width();
|
rx = sw - _window->get_width();
|
||||||
_window->move (rx, ry + _target->get_height());
|
_window->move (rx, ry + _target->get_height());
|
||||||
} else {
|
} else {
|
||||||
_window->move (rx + (_target->get_width () - _window->get_width ()) / 2, ry + _target->get_height());
|
if (_align_to_center) {
|
||||||
|
_window->move (rx + (_target->get_width () - _window->get_width ()) / 2, ry + _target->get_height());
|
||||||
|
} else {
|
||||||
|
_window->move (rx, ry + _target->get_height());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -168,3 +177,19 @@ PersistentTooltip::set_tip (string t)
|
|||||||
_label->set_markup (t);
|
_label->set_markup (t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PersistentTooltip::set_font (Pango::FontDescription font)
|
||||||
|
{
|
||||||
|
_font = font;
|
||||||
|
|
||||||
|
if (_label) {
|
||||||
|
_label->modify_font (_font);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
PersistentTooltip::set_center_alignment (bool align_to_center)
|
||||||
|
{
|
||||||
|
_align_to_center = align_to_center;
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user