Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve displaying tooltip for bbs list/thread list #133

Merged
merged 3 commits into from
Oct 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/manual/2019.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ layout: default

<a name="0.3.0-unreleased"></a>
### [0.3.0-unreleased](https://github.com/JDimproved/JDim/compare/JDim-v0.2.0...master) (unreleased)
- Improve displaying tooltip for bbs list/thread list
([#133](https://github.com/JDimproved/JDim/pull/133))
- Improve displaying manual on github.com
([#132](https://github.com/JDimproved/JDim/pull/132))
- Fix GTKMM_CHECK_VERSION macro
([#131](https://github.com/JDimproved/JDim/pull/131))
- Fix tooltips which are not near mouse pointer on bbs list/thread list for GTK3
([#128](https://github.com/JDimproved/JDim/pull/128))
- Add github links for previous version manuals
Expand Down
40 changes: 31 additions & 9 deletions src/bbslist/bbslistviewbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3159,12 +3159,19 @@ void BBSListViewBase::slot_hide_editlistwin()
bool BBSListViewBase::slot_query_tooltip( int x, int y, bool keyboard_tooltip,
const Glib::RefPtr<Gtk::Tooltip>& tooltip )
{
// NOTE: GTK2版で Gtk::TreeView::get_tooltip_context_path() を使うと
// マウスポインターをヘッダーや空行へ動かしたときに segmentation fault でクラッシュする
Gtk::TreeModel::iterator iter;
if( m_treeview.get_tooltip_context_iter( x, y, keyboard_tooltip, iter ) ) {
if( keyboard_tooltip ) return false;

const Gtk::TreeModel::Path path = m_treestore->get_path( iter );
int bin_x, bin_y;
m_treeview.convert_widget_to_bin_window_coords( x, y, bin_x, bin_y );
#ifdef _DEBUG
std::cout << "BBSListViewBase::slot_query_tooltip"
<< " x(" << x << ") y(" << y << ") bin_x(" << bin_x << ") bin_y(" << bin_y << ")" << std::endl;
#endif

Gtk::TreeModel::Path path;
Gtk::TreeView::Column* column;
int cell_x, cell_y;
if( m_treeview.get_path_at_pos( bin_x, bin_y, path, column, cell_x, cell_y ) ) {
m_treeview.set_tooltip_row( tooltip, path );

const Gtk::TreeModel::Row row = m_treeview.get_row( path );
Expand All @@ -3177,10 +3184,25 @@ bool BBSListViewBase::slot_query_tooltip( int x, int y, bool keyboard_tooltip,
// 画像ポップアップはslot_motion_notifyでセットする
if( type == TYPE_IMAGE ) return false;

// ツールチップ
m_treeview.hide_popup();
tooltip->set_text( subject );
return true;
Gdk::Rectangle cell_area;
m_treeview.get_cell_area( path, *column, cell_area );
const int capacity_width = m_treeview.get_width() - cell_area.get_x();

const auto layout = m_treeview.create_pango_layout( subject );
int pixel_width, ph;
layout->get_pixel_size( pixel_width, ph );

constexpr int icon_size{ 16 };
#ifdef _DEBUG
std::cout << "BBSListViewBase::slot_query_tooltip" << " pixel_width(" << pixel_width
<< ") + icon_size(" << icon_size << ")" << " > capacity_width(" << capacity_width << ")" << std::endl;
#endif
// 板一覧の幅よりセルの内容が長いならツールチップを表示する
if( pixel_width + icon_size > capacity_width ) {
m_treeview.hide_popup();
tooltip->set_text( subject );
return true;
}
}
m_treeview.hide_popup();
return false;
Expand Down
42 changes: 29 additions & 13 deletions src/board/boardviewbase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2205,21 +2205,37 @@ bool BoardViewBase::slot_scroll_event( GdkEventScroll* event )
bool BoardViewBase::slot_query_tooltip( int x, int y, bool keyboard_tooltip,
const Glib::RefPtr<Gtk::Tooltip>& tooltip )
{
// NOTE: GTK2版で Gtk::TreeView::get_tooltip_context_path() を使うと
// マウスポインターをヘッダーや空行へ動かしたときに segmentation fault でクラッシュする
Gtk::TreeModel::iterator iter;
if( m_treeview.get_tooltip_context_iter( x, y, keyboard_tooltip, iter ) ) {
if( keyboard_tooltip ) return false;

const Gtk::TreeModel::Path path = m_liststore->get_path( iter );
m_treeview.set_tooltip_row( tooltip, path );
int bin_x, bin_y;
m_treeview.convert_widget_to_bin_window_coords( x, y, bin_x, bin_y );

const Gtk::TreeModel::Row row = m_treeview.get_row( path );
const Glib::ustring& subject = row[ m_columns.m_col_subject ];

#ifdef _DEBUG
std::cout << "BoardViewBase::slot_query_tooltip subject: " << subject << std::endl;
#endif
tooltip->set_text( subject );
Gtk::TreeModel::Path path;
Gtk::TreeView::Column* column;
int cell_x, cell_y;
if( m_treeview.get_path_at_pos( bin_x, bin_y, path, column, cell_x, cell_y ) ) {
m_treeview.set_tooltip_cell( tooltip, &path, column, nullptr );

const Glib::ustring title = column->get_title();
Glib::ustring cell_text;
if( title == ITEM_NAME_BOARD ) cell_text = get_name_of_cell( path, m_columns.m_col_board );
else if( title == ITEM_NAME_NAME ) cell_text = get_name_of_cell( path, m_columns.m_col_subject );
else if( title == ITEM_NAME_SINCE ) cell_text = get_name_of_cell( path, m_columns.m_col_since );
else if( title == ITEM_NAME_LASTWRITE ) cell_text = get_name_of_cell( path, m_columns.m_col_write );
else if( title == ITEM_NAME_ACCESS ) cell_text = get_name_of_cell( path, m_columns.m_col_access );

// セルの内容が空ならツールチップを表示しない
if( cell_text.empty() ) return false;

const auto layout = m_treeview.create_pango_layout( cell_text );
int pixel_width, ph;
layout->get_pixel_size( pixel_width, ph );
constexpr int offset{ 8 };
// セルの内容の幅が列幅より小さいならツールチップを表示しない
if( pixel_width + offset < column->get_width() ) return false;

// ツールチップにセルの内容をセットする
tooltip->set_text( cell_text );
return true;
}
return false;
Expand Down