557 lines
15 KiB
C++
557 lines
15 KiB
C++
//! \file piscreentiles.h
|
||
//! \ingroup Console
|
||
//! \brief
|
||
//! \~english Various tiles for PIScreen
|
||
//! \~russian Различные тайлы для PIScreen
|
||
//! \details
|
||
//! \~english Provides ready-to-use tile implementations for common UI elements.
|
||
//! \~russian Обеспечивает готовые к использованию реализации тайлов для общих элементов UI.
|
||
/*
|
||
PIP - Platform Independent Primitives
|
||
Various tiles for PIScreen
|
||
Ivan Pelipenko peri4ko@yandex.ru
|
||
|
||
This program 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.
|
||
|
||
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 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/>.
|
||
*/
|
||
|
||
#ifndef PISCREENTILES_H
|
||
#define PISCREENTILES_H
|
||
|
||
#include "pip_console_export.h"
|
||
#include "piscreentile.h"
|
||
|
||
|
||
//! \brief
|
||
//! \~english Tile for displaying simple text content
|
||
//! \~russian Тайл для отображения простого текстового контента
|
||
class PIP_CONSOLE_EXPORT TileSimple: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileSimple, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief Row type
|
||
typedef PIPair<PIString, PIScreenTypes::CellFormat> Row;
|
||
|
||
//! \brief
|
||
//! \~english Constructs TileSimple
|
||
//! \~russian Создает TileSimple
|
||
//! \param n Tile name / Имя тайла
|
||
TileSimple(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Constructs TileSimple with row
|
||
//! \~russian Создает TileSimple со строкой
|
||
//! \param r Row content / Содержимое строки
|
||
TileSimple(const Row & r);
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileSimple() {}
|
||
|
||
//! \brief Tile content rows
|
||
PIVector<Row> content;
|
||
|
||
//! \brief Text alignment
|
||
PIScreenTypes::Alignment alignment;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
};
|
||
|
||
|
||
class TileList;
|
||
|
||
//! \brief
|
||
//! \~english Scrollbar for list containers
|
||
//! \~russian Полоса прокрутки для списков
|
||
class PIP_CONSOLE_EXPORT TileScrollBar: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileScrollBar, PIScreenTile);
|
||
friend class TileList;
|
||
|
||
public:
|
||
//! \brief
|
||
//! \~english Constructs TileScrollBar
|
||
//! \~russian Создает TileScrollBar
|
||
//! \param n Tile name / Имя тайла
|
||
TileScrollBar(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileScrollBar() {}
|
||
|
||
//! \brief
|
||
//! \~english Sets minimum value
|
||
//! \~russian Устанавливает минимальное значение
|
||
void setMinimum(int v);
|
||
|
||
//! \brief
|
||
//! \~english Sets maximum value
|
||
//! \~russian Устанавливает максимальное значение
|
||
void setMaximum(int v);
|
||
|
||
//! \brief
|
||
//! \~english Sets current value
|
||
//! \~russian Устанавливает текущее значение
|
||
void setValue(int v);
|
||
|
||
//! \brief
|
||
//! \~english Returns minimum value
|
||
//! \~russian Возвращает минимальное значение
|
||
int minimum() const { return minimum_; }
|
||
|
||
//! \brief
|
||
//! \~english Returns maximum value
|
||
//! \~russian Возвращает максимальное значение
|
||
int maximum() const { return maximum_; }
|
||
|
||
//! \brief
|
||
//! \~english Returns current value
|
||
//! \~russian Возвращает текущее значение
|
||
int value() const { return value_; }
|
||
|
||
//! \brief Scrollbar thickness
|
||
int thickness;
|
||
|
||
protected:
|
||
//! \brief Validates scrollbar state
|
||
//! \~english Validates scrollbar state
|
||
//! \~russian Проверяет состояние полосы прокрутки
|
||
void _check();
|
||
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles mouse events
|
||
//! \~russian Обрабатывает события мыши
|
||
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||
int minimum_, maximum_, value_;
|
||
PIChar line_char;
|
||
};
|
||
|
||
|
||
//! \brief
|
||
//! \~english Scrollable list tile
|
||
//! \~russian Прокручиваемый список
|
||
class PIP_CONSOLE_EXPORT TileList: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileList, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief Selection mode
|
||
enum SelectionMode {
|
||
NoSelection, //!< No selection / Без выделения
|
||
SingleSelection, //!< Single item selection / Выделение одного элемента
|
||
MultiSelection //!< Multiple items selection / Выделение нескольких элементов
|
||
};
|
||
|
||
//! \brief Event type
|
||
enum EventType {
|
||
SelectionChanged, //!< Selection changed / Выделение изменено
|
||
RowPressed //!< Row pressed / Строка нажата
|
||
};
|
||
|
||
//! \brief
|
||
//! \~english Constructs TileList
|
||
//! \~russian Создает TileList
|
||
//! \param n Tile name / Имя тайла
|
||
//! \param sm Selection mode / Режим выделения
|
||
TileList(const PIString & n = PIString(), SelectionMode sm = NoSelection);
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileList() {}
|
||
|
||
//! \brief Row type
|
||
typedef PIPair<PIString, PIScreenTypes::CellFormat> Row;
|
||
|
||
//! \brief List content
|
||
PIDeque<Row> content;
|
||
|
||
//! \brief Text alignment
|
||
PIScreenTypes::Alignment alignment;
|
||
|
||
//! \brief Selection mode
|
||
SelectionMode selection_mode;
|
||
|
||
//! \brief Selected indices
|
||
PISet<int> selected;
|
||
|
||
//! \brief Line height
|
||
int lhei, cur, offset;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Called when resized
|
||
//! \~russian Вызывается при изменении размера
|
||
void resizeEvent(int w, int h) override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles key events
|
||
//! \~russian Обрабатывает события клавиатуры
|
||
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles mouse events
|
||
//! \~russian Обрабатывает события мыши
|
||
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles wheel events
|
||
//! \~russian Обрабатывает события колеса
|
||
bool wheelEvent(PIKbdListener::WheelEvent we) override;
|
||
TileScrollBar * scroll;
|
||
bool mouse_sel;
|
||
};
|
||
|
||
|
||
//! \brief
|
||
//! \~english Clickable button tile
|
||
//! \~russian Кликабельная кнопка
|
||
class PIP_CONSOLE_EXPORT TileButton: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileButton, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief
|
||
//! \~english Constructs TileButton
|
||
//! \~russian Создает TileButton
|
||
//! \param n Tile name / Имя тайла
|
||
TileButton(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileButton() {}
|
||
|
||
//! \brief Event type
|
||
enum EventType {
|
||
ButtonClicked //!< Button clicked / Кнопка нажата
|
||
};
|
||
|
||
//! \brief Button format
|
||
PIScreenTypes::CellFormat format;
|
||
|
||
//! \brief Button text
|
||
PIString text;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles key events
|
||
//! \~russian Обрабатывает события клавиатуры
|
||
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles mouse events
|
||
//! \~russian Обрабатывает события мыши
|
||
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||
};
|
||
|
||
|
||
//! \brief
|
||
//! \~english Group of buttons with selection
|
||
//! \~russian Группа кнопок с выбором
|
||
|
||
class PIP_CONSOLE_EXPORT TileButtons: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileButtons, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief
|
||
//! \~english Constructs TileButtons
|
||
//! \~russian Создает TileButtons
|
||
//! \param n Tile name / Имя тайла
|
||
TileButtons(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileButtons() {}
|
||
|
||
//! \brief Event type
|
||
enum EventType {
|
||
ButtonSelected //!< Button selected / Кнопка выбрана
|
||
};
|
||
|
||
//! \brief Button type
|
||
typedef PIPair<PIString, PIScreenTypes::CellFormat> Button;
|
||
|
||
//! \brief Button alignment
|
||
PIScreenTypes::Alignment alignment;
|
||
|
||
//! \brief Button content
|
||
PIVector<Button> content;
|
||
|
||
//! \brief Current selection
|
||
int cur;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles key events
|
||
//! \~russian Обрабатывает события клавиатуры
|
||
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles mouse events
|
||
//! \~russian Обрабатывает события мыши
|
||
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||
|
||
//! \brief Button rectangle
|
||
struct Rect {
|
||
Rect(int _x0 = 0, int _y0 = 0, int _x1 = 0, int _y1 = 0): x0(_x0), y0(_y0), x1(_x1), y1(_y1) {}
|
||
int x0, y0, x1, y1;
|
||
};
|
||
PIVector<Rect> btn_rects;
|
||
};
|
||
|
||
|
||
//! \brief
|
||
//! \~english Checkbox with toggle state
|
||
//! \~russian Флажок с переключаемым состоянием
|
||
class PIP_CONSOLE_EXPORT TileCheck: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileCheck, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief
|
||
//! \~english Constructs TileCheck
|
||
//! \~russian Создает TileCheck
|
||
//! \param n Tile name / Имя тайла
|
||
TileCheck(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileCheck() {}
|
||
|
||
//! \brief Event type
|
||
enum EventType {
|
||
Toggled //!< State toggled / Состояние переключено
|
||
};
|
||
|
||
//! \brief Checkbox format
|
||
PIScreenTypes::CellFormat format;
|
||
|
||
//! \brief Checkbox text
|
||
PIString text;
|
||
|
||
//! \brief Checkbox state
|
||
bool toggled;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles key events
|
||
//! \~russian Обрабатывает события клавиатуры
|
||
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles mouse events
|
||
//! \~russian Обрабатывает события мыши
|
||
bool mouseEvent(PIKbdListener::MouseEvent me) override;
|
||
};
|
||
|
||
|
||
//! \brief
|
||
//! \~english Progress bar for displaying progress
|
||
//! \~russian Индикатор прогресса
|
||
class PIP_CONSOLE_EXPORT TileProgress: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileProgress, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief
|
||
//! \~english Constructs TileProgress
|
||
//! \~russian Создает TileProgress
|
||
//! \param n Tile name / Имя тайла
|
||
TileProgress(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileProgress() {}
|
||
|
||
//! \brief Progress format
|
||
PIScreenTypes::CellFormat format;
|
||
|
||
//! \brief Prefix text
|
||
PIString prefix;
|
||
|
||
//! \brief Suffix text
|
||
PIString suffix;
|
||
|
||
//! \brief Maximum value
|
||
double maximum;
|
||
|
||
//! \brief Current value
|
||
double value;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
};
|
||
|
||
|
||
//! \brief
|
||
//! \~english Tile for displaying console output
|
||
//! \~russian Тайл для отображения консольного вывода
|
||
|
||
class PIP_CONSOLE_EXPORT TilePICout: public TileList {
|
||
PIOBJECT_SUBCLASS(TilePICout, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief
|
||
//! \~english Constructs TilePICout
|
||
//! \~russian Создает TilePICout
|
||
//! \param n Tile name / Имя тайла
|
||
TilePICout(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TilePICout() {}
|
||
|
||
//! \brief Output format
|
||
PIScreenTypes::CellFormat format;
|
||
|
||
//! \brief Maximum lines
|
||
int max_lines;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles key events
|
||
//! \~russian Обрабатывает события клавиатуры
|
||
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||
};
|
||
|
||
|
||
//! \brief
|
||
//! \~english Text input tile
|
||
//! \~russian Тайл текстового ввода
|
||
|
||
class PIP_CONSOLE_EXPORT TileInput: public PIScreenTile {
|
||
PIOBJECT_SUBCLASS(TileInput, PIScreenTile);
|
||
|
||
public:
|
||
//! \brief
|
||
//! \~english Constructs TileInput
|
||
//! \~russian Создает TileInput
|
||
//! \param n Tile name / Имя тайла
|
||
TileInput(const PIString & n = PIString());
|
||
|
||
//! \brief
|
||
//! \~english Destructor
|
||
//! \~russian Деструктор
|
||
virtual ~TileInput() {}
|
||
|
||
//! \brief Input format
|
||
PIScreenTypes::CellFormat format;
|
||
|
||
//! \brief Input text
|
||
PIString text;
|
||
|
||
//! \brief Maximum text length
|
||
int max_length;
|
||
|
||
protected:
|
||
//! \brief
|
||
//! \~english Calculates tile size hint
|
||
//! \~russian Вычисляет рекомендуемый размер тайла
|
||
void sizeHint(int & w, int & h) const override;
|
||
|
||
//! \brief
|
||
//! \~english Draws tile content
|
||
//! \~russian Рисует содержимое тайла
|
||
void drawEvent(PIScreenDrawer * d) override;
|
||
|
||
//! \brief
|
||
//! \~english Handles key events
|
||
//! \~russian Обрабатывает события клавиатуры
|
||
bool keyEvent(PIKbdListener::KeyEvent key) override;
|
||
|
||
//! \brief
|
||
//! \~english Resets cursor position
|
||
//! \~russian Сбрасывает позицию курсора
|
||
void reserCursor();
|
||
int cur, offset;
|
||
bool inv;
|
||
PITimeMeasurer tm_blink;
|
||
};
|
||
|
||
|
||
#endif // PISCREENTILES_H
|