InfoBox: extract into dedicated widget
This commit is contained in:
parent
ee67e4914c
commit
5b445a2361
4 changed files with 129 additions and 25 deletions
|
|
@ -40,8 +40,7 @@ namespace panel{
|
|||
, twoParts_{Gtk::ORIENTATION_VERTICAL}
|
||||
, buttons_{}
|
||||
, frame_{"UI Integration Experiments"}
|
||||
, scroller_{}
|
||||
, textLog_{}
|
||||
, errorLog_{}
|
||||
{
|
||||
twoParts_.pack_start(frame_);
|
||||
twoParts_.pack_start(buttons_, Gtk::PACK_SHRINK);
|
||||
|
|
@ -57,17 +56,8 @@ namespace panel{
|
|||
buttons_.add (button_1_);
|
||||
//(End)buttons...
|
||||
|
||||
frame_.add (scroller_);
|
||||
frame_.set_border_width (5);
|
||||
|
||||
scroller_.set_shadow_type (Gtk::SHADOW_NONE);
|
||||
scroller_.set_border_width (10);
|
||||
|
||||
// the vertical scrollbar will always be necessary....
|
||||
scroller_.set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
|
||||
scroller_.add (textLog_);
|
||||
|
||||
textLog_.set_editable (false);
|
||||
frame_.add (errorLog_);
|
||||
|
||||
// show everything....
|
||||
this->add (twoParts_);
|
||||
|
|
@ -96,15 +86,7 @@ namespace panel{
|
|||
static uint bangNo{0};
|
||||
static _Fmt msgTemplate{"Bang #%d\n"};
|
||||
|
||||
// According to the Gtkmm tutorial, TextView::scroll_to(iter) is not reliable;
|
||||
// rather we need to use a text mark and set that text mark to the insert position.
|
||||
// Actually, there is always one predefined text mark called "insert", which corresponds
|
||||
// to the text cursor. Thus it suffices to navigate to text end, insert and scroll into view.
|
||||
auto buff = textLog_.get_buffer();
|
||||
auto cursor = buff->get_insert();
|
||||
buff->move_mark (cursor, buff->end());
|
||||
buff->insert (buff->end(), ustring{msgTemplate % ++bangNo});
|
||||
textLog_.scroll_to (cursor);
|
||||
errorLog_.showMsg(NOTE_WARN, msgTemplate % ++bangNo);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
|
||||
|
||||
#include "gui/panel/panel.hpp"
|
||||
#include "gui/widget/error-log-widget.hpp"
|
||||
|
||||
namespace gui {
|
||||
namespace panel{
|
||||
|
|
@ -61,9 +62,7 @@ namespace panel{
|
|||
Gtk::ButtonBox buttons_;
|
||||
Gtk::Button button_1_;
|
||||
Gtk::Frame frame_;
|
||||
Gtk::ScrolledWindow scroller_;
|
||||
Gtk::TextView textLog_; ////////////TICKET #1047 : as a temporary solution, host the error log here
|
||||
////////////////////////////////////////////////TICKET #1102 : build a message display box widget
|
||||
widget::ErrorLogWidget errorLog_;
|
||||
|
||||
void experiment_1();
|
||||
};
|
||||
|
|
|
|||
121
src/gui/widget/error-log-widget.hpp
Normal file
121
src/gui/widget/error-log-widget.hpp
Normal file
|
|
@ -0,0 +1,121 @@
|
|||
/*
|
||||
ERROR-LOG-WIDGET.hpp - display of error messages in a text box
|
||||
|
||||
Copyright (C) Lumiera.org
|
||||
2017, Hermann Vosseler <Ichthyostega@web.de>
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License as
|
||||
published by the Free Software Foundation; either version 2 of
|
||||
the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
/** @file error-log-widget.hpp
|
||||
** Widget to display error messages to the use in non-modal way.
|
||||
** Notifications are shown in a simple text window with scrollbars; new
|
||||
** entries can be added with a severity level, causing the widget to scroll
|
||||
** down to the last line of the content buffer.
|
||||
**
|
||||
** @todo WIP-WIP-WIP as of 9/2017 this is a first draft of a widget to be
|
||||
** used as receiver by the GuiNotificationService.
|
||||
**
|
||||
*/
|
||||
|
||||
|
||||
#ifndef GUI_WIDGET_ERROR_LOG_WIDGET_H
|
||||
#define GUI_WIDGET_ERROR_LOG_WIDGET_H
|
||||
|
||||
#include "gui/gtk-base.hpp"
|
||||
#include "include/gui-notification-facade.h"
|
||||
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
//#include <memory>
|
||||
//#include <vector>
|
||||
|
||||
|
||||
|
||||
namespace gui {
|
||||
namespace widget {
|
||||
|
||||
|
||||
/**
|
||||
* @todo WIP-WIP as of 9/2017
|
||||
* Just a text display box with scrollbars.
|
||||
* Need to add formatting etc.
|
||||
*/
|
||||
class ErrorLogWidget
|
||||
: public Gtk::ScrolledWindow
|
||||
{
|
||||
public:
|
||||
~ErrorLogWidget() { };
|
||||
|
||||
ErrorLogWidget()
|
||||
: Gtk::ScrolledWindow()
|
||||
, textLog_{}
|
||||
{
|
||||
set_size_request (200, 50);
|
||||
set_border_width (10);
|
||||
set_shadow_type (Gtk::SHADOW_NONE);
|
||||
|
||||
// the vertical scrollbar will always be necessary....
|
||||
set_policy (Gtk::POLICY_AUTOMATIC, Gtk::POLICY_ALWAYS);
|
||||
this->add (textLog_);
|
||||
textLog_.set_editable (false);
|
||||
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
showMsg (NotifyLevel severity, string const& text)
|
||||
{
|
||||
//////////////////////////////////////////////////TICKET #1102 : add formatting according to the error level
|
||||
switch (severity) {
|
||||
case NOTE_ERROR:
|
||||
addEntry ("ERROR: "+text);
|
||||
break;
|
||||
case NOTE_WARN:
|
||||
addEntry ("WARN: "+text);
|
||||
break;
|
||||
default:
|
||||
addEntry (text);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private:/* ===== Internals ===== */
|
||||
|
||||
Gtk::TextView textLog_;
|
||||
|
||||
/** add message entry to the (ever growing) text buffer.
|
||||
* @remark According to the Gtkmm tutorial, TextView::scroll_to(iter) is not reliable;
|
||||
* rather we need to use a text mark and set that text mark to the insert position.
|
||||
* Actually, there is always one predefined text mark called "insert", which corresponds
|
||||
* to the text cursor. Thus it suffices to navigate to text end, insert and scroll into view.
|
||||
*/
|
||||
void
|
||||
addEntry (string const& text)
|
||||
{
|
||||
auto buff = textLog_.get_buffer();
|
||||
auto cursor = buff->get_insert();
|
||||
buff->move_mark (cursor, buff->end());
|
||||
buff->insert (buff->end(), text);
|
||||
textLog_.scroll_to (cursor);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}}// namespace gui::widget
|
||||
#endif /*GUI_WIDGET_ERROR_LOG_WIDGET_H*/
|
||||
|
|
@ -1416,8 +1416,10 @@
|
|||
</node>
|
||||
</node>
|
||||
</node>
|
||||
<node CREATED="1504203763606" ID="ID_877984616" MODIFIED="1504306254735" TEXT="in ein Widget verpacken">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node CREATED="1504203754175" ID="ID_580465154" MODIFIED="1504203763065" TEXT="Fehler-Level erkennen"/>
|
||||
<node CREATED="1504203763606" ID="ID_877984616" MODIFIED="1504203769745" TEXT="in ein Widget verpacken"/>
|
||||
</node>
|
||||
</node>
|
||||
</node>
|
||||
|
|
|
|||
Loading…
Reference in a new issue