2017-11-04 07:03:53 +01:00
|
|
|
/***********************************************************************
|
|
|
|
* ftooltip.cpp - Widget FToolTip *
|
|
|
|
* *
|
|
|
|
* This file is part of the Final Cut widget toolkit *
|
|
|
|
* *
|
2020-02-02 22:34:27 +01:00
|
|
|
* Copyright 2016-2020 Markus Gans *
|
2017-11-04 07:03:53 +01:00
|
|
|
* *
|
|
|
|
* The 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 *
|
|
|
|
* the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* The Final Cut 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 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)
|
|
|
|
: FWindow(parent)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FToolTip::FToolTip (const FString& txt, FWidget* parent)
|
|
|
|
: FWindow(parent)
|
|
|
|
, text(txt)
|
|
|
|
{
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
FToolTip::~FToolTip() // destructor
|
|
|
|
{
|
2020-02-02 22:34:27 +01:00
|
|
|
const auto& fapp = FApplication::getApplicationObject();
|
2016-10-01 23:18:49 +02:00
|
|
|
|
2016-10-17 08:44:38 +02:00
|
|
|
if ( fapp->isQuit() )
|
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FToolTip::show()
|
|
|
|
{
|
|
|
|
if ( ! isVisible() )
|
|
|
|
return;
|
|
|
|
|
|
|
|
FWindow::show();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FToolTip::hide()
|
|
|
|
{
|
|
|
|
FWindow::hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
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
|
2019-01-21 03:42:18 +01:00
|
|
|
setGeometry (FPoint(1, 1), FSize(3, 3), false);
|
|
|
|
setMinimumSize (FSize(3, 3));
|
2019-09-28 03:13:06 +02:00
|
|
|
const auto& wc = getFWidgetColors();
|
2016-11-02 00:37:58 +01:00
|
|
|
setForegroundColor (wc.tooltip_fg);
|
|
|
|
setBackgroundColor (wc.tooltip_bg);
|
2016-10-01 23:18:49 +02:00
|
|
|
calculateDimensions();
|
|
|
|
}
|
|
|
|
|
2019-12-16 11:14:24 +01:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
void FToolTip::draw()
|
|
|
|
{
|
|
|
|
int y{0};
|
|
|
|
setColor();
|
|
|
|
clearArea();
|
|
|
|
drawBorder();
|
|
|
|
|
|
|
|
for (auto&& line : text_components)
|
|
|
|
{
|
|
|
|
print() << FPoint(3, 2 + y) << line;
|
|
|
|
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-02-02 22:34:27 +01:00
|
|
|
int x{}, y{};
|
|
|
|
const std::size_t h = text_num_lines + 2;
|
|
|
|
const std::size_t w = max_line_width + 4;
|
|
|
|
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;
|
|
|
|
|
2019-01-21 03:42:18 +01: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
|