Files
pip/libs/main/console/piscreentile.h

231 lines
7.4 KiB
C++

//! \file piscreentile.h
//! \ingroup Console
//! \brief
//! \~english Basic PIScreen tile
//! \~russian Базовый тайл для PIScreen
//! \details
//! \~english Base class for all screen tiles providing layout and event handling.
//! \~russian Базовый класс для всех экранных тайлов, обеспечивающий компоновку и обработку событий.
/*
PIP - Platform Independent Primitives
Basic PIScreen tile
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 PISCREENTILE_H
#define PISCREENTILE_H
#include "pikbdlistener.h"
#include "pip_console_export.h"
#include "piscreentypes.h"
class PIScreenDrawer;
//! \brief
//! \~english Base tile class for console screen
//! \~russian Базовый класс тайла для консольного экрана
class PIP_CONSOLE_EXPORT PIScreenTile: public PIObject {
friend class PIScreen;
PIOBJECT_SUBCLASS(PIScreenTile, PIObject);
public:
//! \brief
//! \~english Constructs PIScreenTile
//! \~russian Создает PIScreenTile
//! \param n Tile name / Имя тайла
//! \param d Layout direction / Направление компоновки
//! \param p Size policy / Политика размера
PIScreenTile(const PIString & n = PIString(),
PIScreenTypes::Direction d = PIScreenTypes::Vertical,
PIScreenTypes::SizePolicy p = PIScreenTypes::Preferred);
//! \brief
//! \~english Destructor
//! \~russian Деструктор
virtual ~PIScreenTile();
//! \brief
//! \~english Adds child tile
//! \~russian Добавляет дочерний тайл
void addTile(PIScreenTile * t);
//! \brief
//! \~english Takes ownership of tile
//! \~russian Забирает владение тайла
void takeTile(PIScreenTile * t);
//! \brief
//! \~english Removes child tile
//! \~russian Удаляет дочерний тайл
void removeTile(PIScreenTile * t);
//! \brief
//! \~english Returns parent tile
//! \~russian Возвращает родительский тайл
PIScreenTile * parentTile() const { return parent; }
//! \brief
//! \~english Returns child tiles
//! \~russian Возвращает дочерние тайлы
//! \param only_visible Only visible tiles / Только видимые тайлы
PIVector<PIScreenTile *> children(bool only_visible = false);
//! \brief
//! \~english Returns child under mouse position
//! \~russian Возвращает тайл под мышью
PIScreenTile * childUnderMouse(int x, int y);
//! \brief
//! \~english Shows tile
//! \~russian Показывает тайл
void show() { visible = true; }
//! \brief
//! \~english Hides tile
//! \~russian Скрывает тайл
void hide() { visible = false; }
//! \brief
//! \~english Sets focus to this tile
//! \~russian Устанавливает фокус на этот тайл
void setFocus();
//! \brief
//! \~english Checks if tile has focus
//! \~russian Проверяет, имеет ли тайл фокус
bool hasFocus() const { return has_focus; }
//! \brief
//! \~english Sets all margins
//! \~russian Устанавливает все отступы
void setMargins(int m) { marginLeft = marginRight = marginTop = marginBottom = m; }
//! \brief
//! \~english Sets individual margins
//! \~russian Устанавливает отдельные отступы
void setMargins(int l, int r, int t, int b) {
marginLeft = l;
marginRight = r;
marginTop = t;
marginBottom = b;
}
//! \brief
//! \~english Returns tile X position
//! \~russian Возвращает позицию X тайла
int x() const { return x_; }
//! \brief
//! \~english Returns tile Y position
//! \~russian Возвращает позицию Y тайла
int y() const { return y_; }
//! \brief
//! \~english Returns tile width
//! \~russian Возвращает ширину тайла
int width() const { return width_; }
//! \brief
//! \~english Returns tile height
//! \~russian Возвращает высоту тайла
int height() const { return height_; }
PIScreenTypes::Direction direction;
PIScreenTypes::SizePolicy size_policy;
PIScreenTypes::FocusFlags focus_flags;
PIScreenTypes::CellFormat back_format;
PIChar back_symbol;
int minimumWidth, minimumHeight;
int maximumWidth, maximumHeight;
int marginLeft, marginRight, marginTop, marginBottom;
int spacing;
bool visible;
protected:
//! \brief
//! \~english Returns desired tile size in "w" and "h"
//! \~russian Возвращает желаемый размер тайла в "w" и "h"
virtual void sizeHint(int & w, int & h) const;
//! \brief
//! \~english Tile has been resized to "w"x"h"
//! \~russian Тайл был изменен на "w"x"h"
virtual void resizeEvent(int w, int h) {}
//! \brief
//! \~english Draw tile with drawer "d" in world-space coordinates
//! \~russian Рисует тайл отрисовщиком "d" в мировых координатах
virtual void drawEvent(PIScreenDrawer * d) {}
//! \brief
//! \~english Return "true" if you process key
//! \~russian Возвращает "true" если вы обрабатываете клавишу
virtual bool keyEvent(PIKbdListener::KeyEvent key) { return false; }
//! \brief
//! \~english Return "true" if you process event
//! \~russian Возвращает "true" если вы обрабатываете событие
virtual bool mouseEvent(PIKbdListener::MouseEvent me) { return false; }
//! \brief
//! \~english Return "true" if you process wheel
//! \~russian Возвращает "true" если вы обрабатываете колесо
virtual bool wheelEvent(PIKbdListener::WheelEvent we) { return false; }
//! \brief
//! \~english Raises tile event
//! \~russian Вызывает событие тайла
void raiseEvent(PIScreenTypes::TileEvent e);
//! \brief
//! \~english Sets screen reference
//! \~russian Устанавливает ссылку на экран
void setScreen(PIScreenTypes::PIScreenBase * s);
//! \brief
//! \~english Deletes all children
//! \~russian Удаляет всех потомков
void deleteChildren();
//! \brief
//! \~english Internal draw event
//! \~russian Внутреннее событие отрисовки
void drawEventInternal(PIScreenDrawer * d);
//! \brief
//! \~english Performs layout
//! \~russian Выполняет компоновку
void layout();
//! \brief
//! \~english Checks if layout is needed
//! \~russian Проверяет, нужна ли компоновка
bool needLayout() { return size_policy != PIScreenTypes::Ignore; }
PIVector<PIScreenTile *> tiles;
PIScreenTile * parent;
PIScreenTypes::PIScreenBase * screen;
int x_, y_, width_, height_;
bool has_focus;
private:
int pw, ph;
};
#endif // PISCREENTILE_H