2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ftooltip.cpp - Widget FToolTip *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* This file is part of the FINAL CUT widget toolkit *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2016-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is free software; you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation; either version 3 of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
2020-07-08 21:32:47 +02:00
|
|
|
* FINAL CUT is distributed in the hope that it will be useful, but *
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of *
|
2017-11-04 07:03:53 +01:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public *
|
|
|
|
* License along with this program. If not, see *
|
|
|
|
* <http://www.gnu.org/licenses/>. *
|
|
|
|
***********************************************************************/
|
2016-10-01 23:18:49 +02:00
|
|
|
|
2017-09-17 21:32:46 +02:00
|
|
|
#include "final/fapplication.h"
|
|
|
|
#include "final/ftooltip.h"
|
2019-07-21 23:31:21 +02:00
|
|
|
#include "final/fwidgetcolors.h"
|
2016-10-01 23:18:49 +02:00
|
|
|
|
2018-09-20 23:59:01 +02:00
|
|
|
namespace finalcut
|
|
|
|
{
|
2016-10-01 23:18:49 +02:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
// class FToolTip
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
// constructor and destructor
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FToolTip::FToolTip (FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FWindow{parent}
|
2016-10-01 23:18:49 +02:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FToolTip::FToolTip (const FString& txt, FWidget* parent)
|
2020-05-24 23:55:08 +02:00
|
|
|
: FWindow{parent}
|
2020-05-24 02:15:43 +02:00
|
|
|
, text{txt}
|
2016-10-01 23:18:49 +02:00
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FToolTip::~FToolTip() // destructor
|
|
|
|
{
|
2020-04-13 12:40:11 +02:00
|
|
|
if ( FApplication::isQuit() )
|
2016-10-17 08:44:38 +02:00
|
|
|
return;
|
2016-10-01 23:18:49 +02:00
|
|
|
|
2019-08-25 22:16:00 +02:00
|
|
|
FWindow* parent_win{nullptr};
|
2016-10-01 23:18:49 +02:00
|
|
|
|
2018-12-15 00:50:09 +01:00
|
|
|
if ( auto parent = getParentWidget() )
|
2016-10-17 08:44:38 +02:00
|
|
|
parent_win = getWindowWidget(parent);
|
|
|
|
|
|
|
|
if ( parent_win )
|
|
|
|
setActiveWindow (parent_win);
|
|
|
|
else
|
2018-10-29 00:45:45 +01:00
|
|
|
switchToPrevWindow(this);
|
2016-10-01 23:18:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
// public methods of FToolTip
|
2016-10-01 23:18:49 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FToolTip::setText (const FString& txt)
|
2016-10-01 23:18:49 +02:00
|
|
|
{
|
2019-08-25 22:16:00 +02:00
|
|
|
text.setString(txt);
|
2016-10-01 23:18:49 +02:00
|
|
|
calculateDimensions();
|
|
|
|
}
|
|
|
|
|
2020-05-30 23:02:53 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FToolTip::resetColors()
|
|
|
|
{
|
|
|
|
const auto& wc = getColorTheme();
|
|
|
|
setForegroundColor (wc->tooltip_fg);
|
|
|
|
setBackgroundColor (wc->tooltip_bg);
|
|
|
|
FWidget::resetColors();
|
|
|
|
}
|
|
|
|
|
2020-04-09 12:38:35 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
bool FToolTip::setBorder (bool enable)
|
|
|
|
{
|
|
|
|
setFlags().no_border = ! enable;
|
|
|
|
calculateDimensions();
|
|
|
|
return hasBorder();
|
|
|
|
}
|
|
|
|
|
2016-10-01 23:18:49 +02:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FToolTip::show()
|
|
|
|
{
|
|
|
|
if ( ! isVisible() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
FWindow::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FToolTip::onMouseDown (FMouseEvent*)
|
|
|
|
{
|
2019-09-08 02:04:24 +02:00
|
|
|
setClickedWidget(nullptr);
|
2016-10-01 23:18:49 +02:00
|
|
|
close();
|
|
|
|
}
|
|
|
|
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
// private methods of FToolTip
|
2016-10-01 23:18:49 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FToolTip::init()
|
2016-10-01 23:18:49 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
setAlwaysOnTop();
|
|
|
|
ignorePadding();
|
|
|
|
// initialize geometry values
|
2020-05-02 00:07:35 +02:00
|
|
|
setGeometry (FPoint{1, 1}, FSize{3, 3}, false);
|
|
|
|
setMinimumSize (FSize{3, 3});
|
2020-05-30 23:02:53 +02:00
|
|
|
resetColors();
|
2016-10-01 23:18:49 +02:00
|
|
|
calculateDimensions();
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FToolTip::draw()
|
|
|
|
{
|
2020-04-09 12:38:35 +02:00
|
|
|
bool border = hasBorder();
|
|
|
|
int y{( border ) ? 2 : 1};
|
|
|
|
int x{( border ) ? 3 : 2};
|
2019-12-16 11:14:24 +01:00
|
|
|
setColor();
|
|
|
|
clearArea();
|
2020-04-09 12:38:35 +02:00
|
|
|
|
|
|
|
if ( border )
|
|
|
|
drawBorder();
|
2019-12-16 11:14:24 +01:00
|
|
|
|
|
|
|
for (auto&& line : text_components)
|
|
|
|
{
|
2020-05-02 00:07:35 +02:00
|
|
|
print() << FPoint{x, y} << line;
|
2019-12-16 11:14:24 +01:00
|
|
|
y++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-01 23:18:49 +02:00
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FToolTip::calculateDimensions()
|
2016-10-01 23:18:49 +02:00
|
|
|
{
|
2018-12-09 18:24:31 +01:00
|
|
|
max_line_width = 0;
|
2019-09-28 03:13:06 +02:00
|
|
|
text_components = text.split("\n");
|
|
|
|
text_num_lines = std::size_t(text_components.size());
|
2018-12-09 18:24:31 +01:00
|
|
|
|
|
|
|
if ( text_num_lines == 0 )
|
|
|
|
return;
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
for (auto&& line : text_components)
|
2016-11-02 00:37:58 +01:00
|
|
|
{
|
2019-09-28 03:13:06 +02:00
|
|
|
std::size_t column_width = getColumnWidth(line);
|
2016-11-02 00:37:58 +01:00
|
|
|
|
2019-09-28 03:13:06 +02:00
|
|
|
if ( column_width > max_line_width )
|
|
|
|
max_line_width = column_width;
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
|
2020-04-13 12:40:11 +02:00
|
|
|
int x{};
|
|
|
|
int y{};
|
2020-04-09 12:38:35 +02:00
|
|
|
const std::size_t h = ( hasBorder() ) ? text_num_lines + 2 : text_num_lines;
|
|
|
|
const std::size_t w = ( hasBorder() ) ? max_line_width + 4 : max_line_width + 2;
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& r = getRootWidget();
|
2016-11-02 00:37:58 +01:00
|
|
|
|
|
|
|
if ( r )
|
|
|
|
{
|
2017-08-27 09:50:30 +02:00
|
|
|
x = 1 + int((r->getWidth() - w) / 2);
|
|
|
|
y = 1 + int((r->getHeight() - h) / 2);
|
2016-11-02 00:37:58 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
x = y = 1;
|
|
|
|
|
2020-05-02 00:07:35 +02:00
|
|
|
setGeometry (FPoint{x, y}, FSize{w, h});
|
2016-10-01 23:18:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
2016-11-02 00:37:58 +01:00
|
|
|
void FToolTip::adjustSize()
|
2016-10-01 23:18:49 +02:00
|
|
|
{
|
2016-11-02 00:37:58 +01:00
|
|
|
calculateDimensions();
|
|
|
|
FWindow::adjustSize();
|
2016-10-01 23:18:49 +02:00
|
|
|
}
|
2018-09-20 23:59:01 +02:00
|
|
|
|
|
|
|
} // namespace finalcut
|