diff --git a/src/ColorSchemeEditor.h b/src/ColorSchemeEditor.h index 500794ff..459aba3f 100644 --- a/src/ColorSchemeEditor.h +++ b/src/ColorSchemeEditor.h @@ -1,99 +1,99 @@ /* Copyright 2007-2008 by Robert Knight This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef COLORSCHEMEEDITOR_H #define COLORSCHEMEEDITOR_H // Qt #include // KDE #include // Konsole #include "Profile.h" class QTableWidgetItem; namespace Ui { class ColorSchemeEditor; } namespace Konsole { class ColorScheme; /** * A dialog for editing color schemes. * * After creation, the dialog can be initialized with the settings * of a color scheme using the setup() method. * * The dialog creates a copy of the supplied color scheme to which * any changes made are applied. The modified color scheme * can be retrieved using the colorScheme() method. * * When changes are made the colorsChanged() signal is emitted. */ class KONSOLEPRIVATE_EXPORT ColorSchemeEditor : public QDialog { Q_OBJECT public: /** Constructs a new color scheme editor with the specified parent. */ - explicit ColorSchemeEditor(QWidget *parent = 0); + explicit ColorSchemeEditor(QWidget *parent = nullptr); ~ColorSchemeEditor() Q_DECL_OVERRIDE; /** Initializes the dialog with the properties of the specified color scheme. */ void setup(const ColorScheme *scheme, bool isNewScheme); /** Returns the modified color scheme. */ ColorScheme &colorScheme() const; bool isNewScheme() const; Q_SIGNALS: /** Emitted when the colors in the color scheme change. */ void colorsChanged(ColorScheme *scheme); /** Used to send back colorscheme changes into the profile edited */ void colorSchemeSaveRequested(const ColorScheme &scheme, bool isNewScheme); public Q_SLOTS: /** Sets the text displayed in the description edit field. */ void setDescription(const QString &description); private Q_SLOTS: void setTransparencyPercentLabel(int percent); void setBlur(bool blur); void setRandomizedBackgroundColor(bool randomized); void editColorItem(QTableWidgetItem *item); void wallpaperPathChanged(const QString &path); void selectWallpaper(); /** Triggered by apply/ok buttons */ void saveColorScheme(); private: Q_DISABLE_COPY(ColorSchemeEditor) void setupColorTable(const ColorScheme *table); bool _isNewScheme; Ui::ColorSchemeEditor *_ui; ColorScheme *_colors; }; } #endif // COLORSCHEMEEDITOR_H diff --git a/src/History.h b/src/History.h index d5cfb374..670a0fc1 100644 --- a/src/History.h +++ b/src/History.h @@ -1,415 +1,415 @@ /* This file is part of Konsole, an X terminal. Copyright 1997,1998 by Lars Doelle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef HISTORY_H #define HISTORY_H // System #include // Qt #include #include #include #include "konsoleprivate_export.h" // Konsole #include "Character.h" namespace Konsole { /* An extendable tmpfile(1) based buffer. */ class HistoryFile { public: HistoryFile(); virtual ~HistoryFile(); virtual void add(const char *buffer, qint64 count); virtual void get(char *buffer, qint64 size, qint64 loc); virtual qint64 len() const; //mmaps the file in read-only mode void map(); //un-mmaps the file void unmap(); //returns true if the file is mmap'ed bool isMapped() const; private: qint64 _length; QTemporaryFile _tmpFile; //pointer to start of mmap'ed file data, or 0 if the file is not mmap'ed uchar *_fileMap; //incremented whenever 'add' is called and decremented whenever //'get' is called. //this is used to detect when a large number of lines are being read and processed from the history //and automatically mmap the file for better performance (saves the overhead of many lseek-read calls). int _readWriteBalance; //when _readWriteBalance goes below this threshold, the file will be mmap'ed automatically static const int MAP_THRESHOLD = -1000; }; ////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////// // Abstract base class for file and buffer versions ////////////////////////////////////////////////////////////////////// class HistoryType; class KONSOLEPRIVATE_EXPORT HistoryScroll { public: explicit HistoryScroll(HistoryType *); virtual ~HistoryScroll(); virtual bool hasScroll(); // access to history virtual int getLines() = 0; virtual int getLineLen(int lineno) = 0; virtual void getCells(int lineno, int colno, int count, Character res[]) = 0; virtual bool isWrappedLine(int lineNumber) = 0; // adding lines. virtual void addCells(const Character a[], int count) = 0; // convenience method - this is virtual so that subclasses can take advantage // of QVector's implicit copying virtual void addCellsVector(const QVector &cells) { addCells(cells.data(), cells.size()); } virtual void addLine(bool previousWrapped = false) = 0; // // FIXME: Passing around constant references to HistoryType instances // is very unsafe, because those references will no longer // be valid if the history scroll is deleted. // const HistoryType &getType() const { return *_historyType; } protected: HistoryType *_historyType; }; ////////////////////////////////////////////////////////////////////// // File-based history (e.g. file log, no limitation in length) ////////////////////////////////////////////////////////////////////// class KONSOLEPRIVATE_EXPORT HistoryScrollFile : public HistoryScroll { public: explicit HistoryScrollFile(const QString &logFileName); ~HistoryScrollFile() Q_DECL_OVERRIDE; int getLines() Q_DECL_OVERRIDE; int getLineLen(int lineno) Q_DECL_OVERRIDE; void getCells(int lineno, int colno, int count, Character res[]) Q_DECL_OVERRIDE; bool isWrappedLine(int lineno) Q_DECL_OVERRIDE; void addCells(const Character text[], int count) Q_DECL_OVERRIDE; void addLine(bool previousWrapped = false) Q_DECL_OVERRIDE; private: qint64 startOfLine(int lineno); HistoryFile _index; // lines Row(qint64) HistoryFile _cells; // text Row(Character) HistoryFile _lineflags; // flags Row(unsigned char) }; ////////////////////////////////////////////////////////////////////// // Nothing-based history (no history :-) ////////////////////////////////////////////////////////////////////// class KONSOLEPRIVATE_EXPORT HistoryScrollNone : public HistoryScroll { public: HistoryScrollNone(); ~HistoryScrollNone() Q_DECL_OVERRIDE; bool hasScroll() Q_DECL_OVERRIDE; int getLines() Q_DECL_OVERRIDE; int getLineLen(int lineno) Q_DECL_OVERRIDE; void getCells(int lineno, int colno, int count, Character res[]) Q_DECL_OVERRIDE; bool isWrappedLine(int lineno) Q_DECL_OVERRIDE; void addCells(const Character a[], int count) Q_DECL_OVERRIDE; void addLine(bool previousWrapped = false) Q_DECL_OVERRIDE; }; ////////////////////////////////////////////////////////////////////// // History using compact storage // This implementation uses a list of fixed-sized blocks // where history lines are allocated in (avoids heap fragmentation) ////////////////////////////////////////////////////////////////////// typedef QVector TextLine; class CharacterFormat { public: bool equalsFormat(const CharacterFormat &other) const { return (other.rendition & ~RE_EXTENDED_CHAR) == (rendition & ~RE_EXTENDED_CHAR) && other.fgColor == fgColor && other.bgColor == bgColor; } bool equalsFormat(const Character &c) const { return (c.rendition & ~RE_EXTENDED_CHAR) == (rendition & ~RE_EXTENDED_CHAR) && c.foregroundColor == fgColor && c.backgroundColor == bgColor; } void setFormat(const Character &c) { rendition = c.rendition; fgColor = c.foregroundColor; bgColor = c.backgroundColor; isRealCharacter = c.isRealCharacter; } CharacterColor fgColor, bgColor; quint16 startPos; RenditionFlags rendition; bool isRealCharacter; }; class CompactHistoryBlock { public: CompactHistoryBlock() : _blockLength(4096 * 64), // 256kb - _head(static_cast(mmap(0, _blockLength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0))), - _tail(0), - _blockStart(0), + _head(static_cast(mmap(nullptr, _blockLength, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0))), + _tail(nullptr), + _blockStart(nullptr), _allocCount(0) { Q_ASSERT(_head != MAP_FAILED); _tail = _blockStart = _head; } virtual ~CompactHistoryBlock() { //free(_blockStart); munmap(_blockStart, _blockLength); } virtual unsigned int remaining() { return _blockStart + _blockLength - _tail; } virtual unsigned length() { return _blockLength; } virtual void *allocate(size_t size); virtual bool contains(void *addr) { return addr >= _blockStart && addr < (_blockStart + _blockLength); } virtual void deallocate(); virtual bool isInUse() { return _allocCount != 0; } private: size_t _blockLength; quint8 *_head; quint8 *_tail; quint8 *_blockStart; int _allocCount; }; class CompactHistoryBlockList { public: CompactHistoryBlockList() : list(QList()) { } ~CompactHistoryBlockList(); void *allocate(size_t size); void deallocate(void *); int length() { return list.size(); } private: QList list; }; class CompactHistoryLine { public: CompactHistoryLine(const TextLine &, CompactHistoryBlockList &blockList); virtual ~CompactHistoryLine(); // custom new operator to allocate memory from custom pool instead of heap static void *operator new(size_t size, CompactHistoryBlockList &blockList); static void operator delete(void *) { /* do nothing, deallocation from pool is done in destructor*/ } virtual void getCharacters(Character *array, int size, int startColumn); virtual void getCharacter(int index, Character &r); virtual bool isWrapped() const { return _wrapped; } virtual void setWrapped(bool value) { _wrapped = value; } virtual unsigned int getLength() const { return _length; } protected: CompactHistoryBlockList &_blockListRef; CharacterFormat *_formatArray; quint16 _length; quint16 *_text; quint16 _formatLength; bool _wrapped; }; class KONSOLEPRIVATE_EXPORT CompactHistoryScroll : public HistoryScroll { typedef QList HistoryArray; public: explicit CompactHistoryScroll(unsigned int maxNbLines = 1000); ~CompactHistoryScroll() Q_DECL_OVERRIDE; int getLines() Q_DECL_OVERRIDE; int getLineLen(int lineNumber) Q_DECL_OVERRIDE; void getCells(int lineNumber, int startColumn, int count, Character buffer[]) Q_DECL_OVERRIDE; bool isWrappedLine(int lineNumber) Q_DECL_OVERRIDE; void addCells(const Character a[], int count) Q_DECL_OVERRIDE; void addCellsVector(const TextLine &cells) Q_DECL_OVERRIDE; void addLine(bool previousWrapped = false) Q_DECL_OVERRIDE; void setMaxNbLines(unsigned int lineCount); private: bool hasDifferentColors(const TextLine &line) const; HistoryArray _lines; CompactHistoryBlockList _blockList; unsigned int _maxLineCount; }; ////////////////////////////////////////////////////////////////////// // History type ////////////////////////////////////////////////////////////////////// class KONSOLEPRIVATE_EXPORT HistoryType { public: HistoryType(); virtual ~HistoryType(); /** * Returns true if the history is enabled ( can store lines of output ) * or false otherwise. */ virtual bool isEnabled() const = 0; /** * Returns the maximum number of lines which this history type * can store or -1 if the history can store an unlimited number of lines. */ virtual int maximumLineCount() const = 0; /** * Converts from one type of HistoryScroll to another or if given the * same type, returns it. */ virtual HistoryScroll *scroll(HistoryScroll *) const = 0; /** * Returns true if the history size is unlimited. */ bool isUnlimited() const { return maximumLineCount() == -1; } }; class KONSOLEPRIVATE_EXPORT HistoryTypeNone : public HistoryType { public: HistoryTypeNone(); bool isEnabled() const Q_DECL_OVERRIDE; int maximumLineCount() const Q_DECL_OVERRIDE; HistoryScroll *scroll(HistoryScroll *) const Q_DECL_OVERRIDE; }; class KONSOLEPRIVATE_EXPORT HistoryTypeFile : public HistoryType { public: explicit HistoryTypeFile(const QString &fileName = QString()); bool isEnabled() const Q_DECL_OVERRIDE; int maximumLineCount() const Q_DECL_OVERRIDE; HistoryScroll *scroll(HistoryScroll *) const Q_DECL_OVERRIDE; protected: QString _fileName; }; class KONSOLEPRIVATE_EXPORT CompactHistoryType : public HistoryType { public: explicit CompactHistoryType(unsigned int nbLines); bool isEnabled() const Q_DECL_OVERRIDE; int maximumLineCount() const Q_DECL_OVERRIDE; HistoryScroll *scroll(HistoryScroll *) const Q_DECL_OVERRIDE; protected: unsigned int _maxLines; }; } #endif // HISTORY_H diff --git a/src/ScreenWindow.h b/src/ScreenWindow.h index 38c0b01a..64c7ec49 100644 --- a/src/ScreenWindow.h +++ b/src/ScreenWindow.h @@ -1,279 +1,279 @@ /* Copyright 2007-2008 by Robert Knight This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef SCREENWINDOW_H #define SCREENWINDOW_H // Qt #include #include #include // Konsole #include "Character.h" #include "Screen.h" namespace Konsole { /** * Provides a window onto a section of a terminal screen. A terminal widget can then render * the contents of the window and use the window to change the terminal screen's selection * in response to mouse or keyboard input. * * A new ScreenWindow for a terminal session can be created by calling Emulation::createWindow() * * Use the scrollTo() method to scroll the window up and down on the screen. * Use the getImage() method to retrieve the character image which is currently visible in the window. * * setTrackOutput() controls whether the window moves to the bottom of the associated screen when new * lines are added to it. * * Whenever the output from the underlying screen is changed, the notifyOutputChanged() slot should * be called. This in turn will update the window's position and emit the outputChanged() signal * if necessary. */ class ScreenWindow : public QObject { Q_OBJECT public: /** * Constructs a new screen window with the given parent. * A screen must be specified by calling setScreen() before calling getImage() or getLineProperties(). * * You should not call this constructor directly, instead use the Emulation::createWindow() method * to create a window on the emulation which you wish to view. This allows the emulation * to notify the window when the associated screen has changed and synchronize selection updates * between all views on a session. */ - explicit ScreenWindow(Screen *screen, QObject *parent = 0); + explicit ScreenWindow(Screen *screen, QObject *parent = nullptr); ~ScreenWindow() Q_DECL_OVERRIDE; /** Sets the screen which this window looks onto */ void setScreen(Screen *screen); /** Returns the screen which this window looks onto */ Screen *screen() const; /** * Returns the image of characters which are currently visible through this window * onto the screen. * * The returned buffer is managed by the ScreenWindow instance and does not need to be * deleted by the caller. */ Character *getImage(); /** * Returns the line attributes associated with the lines of characters which * are currently visible through this window */ QVector getLineProperties(); /** * Returns the number of lines which the region of the window * specified by scrollRegion() has been scrolled by since the last call * to resetScrollCount(). scrollRegion() is in most cases the * whole window, but will be a smaller area in, for example, applications * which provide split-screen facilities. * * This is not guaranteed to be accurate, but allows views to optimize * rendering by reducing the amount of costly text rendering that * needs to be done when the output is scrolled. */ int scrollCount() const; /** * Resets the count of scrolled lines returned by scrollCount() */ void resetScrollCount(); /** * Returns the area of the window which was last scrolled, this is * usually the whole window area. * * Like scrollCount(), this is not guaranteed to be accurate, * but allows views to optimize rendering. */ QRect scrollRegion() const; /** * What line the next search will start from */ void setCurrentResultLine(int line); int currentResultLine() const; /** * Sets the start of the selection to the given @p line and @p column within * the window. */ void setSelectionStart(int column, int line, bool columnMode); /** * Sets the end of the selection to the given @p line and @p column within * the window. */ void setSelectionEnd(int column, int line); /** * Sets the selection as the range specified by line @p start and line @p * end in the whole history. * * Both @p start and @p end are absolute line number in the whole history, * not relative line number in the window. This make it possible to select * range larger than the window . A good use case is selecting the whole * history. */ void setSelectionByLineRange(int start, int end); /** * Retrieves the start of the selection within the window. */ void getSelectionStart(int &column, int &line); /** * Retrieves the end of the selection within the window. */ void getSelectionEnd(int &column, int &line); /** * Returns true if the character at @p line , @p column is part of the selection. */ bool isSelected(int column, int line); /** * Clears the current selection */ void clearSelection(); /** Sets the number of lines in the window */ void setWindowLines(int lines); /** Returns the number of lines in the window */ int windowLines() const; /** Returns the number of columns in the window */ int windowColumns() const; /** Returns the total number of lines in the screen */ int lineCount() const; /** Returns the total number of columns in the screen */ int columnCount() const; /** Returns the index of the line which is currently at the top of this window */ int currentLine() const; /** * Returns the position of the cursor * within the window. */ QPoint cursorPosition() const; /** * Convenience method. Returns true if the window is currently at the bottom * of the screen. */ bool atEndOfOutput() const; /** Scrolls the window so that @p line is at the top of the window */ void scrollTo(int line); /** Describes the units which scrollBy() moves the window by. */ enum RelativeScrollMode { /** Scroll the window down by a given number of lines. */ ScrollLines, /** * Scroll the window down by a given number of pages, where * one page is windowLines() lines */ ScrollPages }; /** * Scrolls the window relative to its current position on the screen. * * @param mode Specifies whether @p amount refers to the number of lines or the number * of pages to scroll. * @param amount The number of lines or pages ( depending on @p mode ) to scroll by. If * this number is positive, the view is scrolled down. If this number is negative, the view * is scrolled up. * @param fullPage Specifies whether to scroll by full page or half page. */ void scrollBy(RelativeScrollMode mode, int amount, bool fullPage); /** * Specifies whether the window should automatically move to the bottom * of the screen when new output is added. * * If this is set to true, the window will be moved to the bottom of the associated screen ( see * screen() ) when the notifyOutputChanged() method is called. */ void setTrackOutput(bool trackOutput); /** * Returns whether the window automatically moves to the bottom of the screen as * new output is added. See setTrackOutput() */ bool trackOutput() const; /** * Returns the text which is currently selected. * * @param options See Screen::DecodingOptions */ QString selectedText(const Konsole::Screen::DecodingOptions options) const; public Q_SLOTS: /** * Notifies the window that the contents of the associated terminal screen have changed. * This moves the window to the bottom of the screen if trackOutput() is true and causes * the outputChanged() signal to be emitted. */ void notifyOutputChanged(); Q_SIGNALS: /** * Emitted when the contents of the associated terminal screen (see screen()) changes. */ void outputChanged(); void currentResultLineChanged(); /** * Emitted when the screen window is scrolled to a different position. * * @param line The line which is now at the top of the window. */ void scrolled(int line); /** Emitted when the selection is changed. */ void selectionChanged(); private: Q_DISABLE_COPY(ScreenWindow) int endWindowLine() const; void fillUnusedArea(); Screen *_screen; // see setScreen() , screen() Character *_windowBuffer; int _windowBufferSize; bool _bufferNeedsUpdate; int _windowLines; int _currentLine; // see scrollTo() , currentLine() int _currentResultLine; bool _trackOutput; // see setTrackOutput() , trackOutput() int _scrollCount; // count of lines which the window has been scrolled by since // the last call to resetScrollCount() }; } #endif // SCREENWINDOW_H diff --git a/src/ViewContainer.h b/src/ViewContainer.h index ac846298..b687767b 100644 --- a/src/ViewContainer.h +++ b/src/ViewContainer.h @@ -1,487 +1,487 @@ /* This file is part of the Konsole Terminal. Copyright 2006-2008 Robert Knight This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ #ifndef VIEWCONTAINER_H #define VIEWCONTAINER_H // Qt #include #include #include #include // Konsole #include "Profile.h" class QStackedWidget; class QWidget; class QHBoxLayout; class QVBoxLayout; // TabbedViewContainer // Qt class QPoint; class QToolButton; class QMenu; class QDropEvent; // KDE class QMenu; namespace Konsole { class IncrementalSearchBar; class ViewProperties; class TabbedViewContainer; /** * An interface for container widgets which can hold one or more views. * * The container widget typically displays a list of the views which * it has and provides a means of switching between them. * * Subclasses should reimplement the addViewWidget() and removeViewWidget() functions * to actually add or remove view widgets from the container widget, as well * as updating any navigation aids. */ class ViewContainer : public QObject { Q_OBJECT public: /** * This enum describes the options for positioning the * container's navigation widget. */ enum NavigationPosition { /** Position the navigation widget above the views. */ NavigationPositionTop, /** Position the navigation widget below the views. */ NavigationPositionBottom, /** Position the navigation widget to the left of the views. */ NavigationPositionLeft, /** Position the navigation widget to the right of the views. */ NavigationPositionRight }; /** * Constructs a new view container with the specified parent. * * @param position The initial position of the navigation widget * @param parent The parent object of the container */ ViewContainer(NavigationPosition position, QObject *parent); /** * Called when the ViewContainer is destroyed. When reimplementing this in * subclasses, use object->deleteLater() to delete any widgets or other objects * instead of 'delete object'. */ ~ViewContainer() Q_DECL_OVERRIDE; /** Returns the widget which contains the view widgets */ virtual QWidget *containerWidget() const = 0; /** * This enum describes the options for showing or hiding the * container's navigation widget. */ enum NavigationVisibility { /** Always show the navigation widget. */ AlwaysShowNavigation, /** Show the navigation widget only when the container has more than one view. */ ShowNavigationAsNeeded, /** Always hide the navigation widget. */ AlwaysHideNavigation }; /* * Sets the visibility of the view container's navigation widget. * * The ViewContainer sub-class is responsible for ensuring that this * setting is respected as views are added or removed from the * container. * * ViewContainer sub-classes should reimplement the * navigationVisibilityChanged() method to respond to changes * of this property. */ void setNavigationVisibility(NavigationVisibility mode); /** * Returns the current mode for controlling the visibility of the * the view container's navigation widget. */ NavigationVisibility navigationVisibility() const; /** * Sets the position of the navigation widget with * respect to the main content area. * * Depending on the ViewContainer subclass, not all * positions from the NavigationPosition enum may be * supported. A list of supported positions can be * obtained by calling supportedNavigationPositions() * * ViewContainer sub-classes should re-implement the * navigationPositionChanged() method to respond * to changes of this property. */ void setNavigationPosition(NavigationPosition position); /** * Returns the position of the navigation widget with * respect to the main content area. */ NavigationPosition navigationPosition() const; /** * Set whether tab width are expanding */ void setNavigationTabWidthExpanding(bool expand); /** * Returns the list of supported navigation positions. * The supported positions will depend upon the type of the * navigation widget used by the ViewContainer subclass. * * The base implementation returns one item, NavigationPositionTop */ virtual QList supportedNavigationPositions() const; /** Sets the navigation text mode * If mode is true, use the width of the title; otherwise use the * default width calculations. */ void setNavigationTextMode(bool mode); /** Sets the stylesheet for visual appearance * * The default implementation does nothing. */ virtual void setStyleSheet(const QString &styleSheet) { Q_UNUSED(styleSheet); } /** Adds a new view to the container widget */ void addView(QWidget *view, ViewProperties *navigationItem, int index = -1); /** Removes a view from the container */ void removeView(QWidget *view); /** Returns the ViewProperties instance associated with a particular view in the container */ ViewProperties *viewProperties(QWidget *view) const; /** Returns a list of the contained views */ const QList views() const; /** * Returns the view which currently has the focus or 0 if none * of the child views have the focus. */ virtual QWidget *activeView() const = 0; /** * Changes the focus to the specified view and updates * navigation aids to reflect the change. */ virtual void setActiveView(QWidget *widget) = 0; /** * @return the search widget for this view */ IncrementalSearchBar *searchBar(); /** Changes the active view to the next view */ void activateNextView(); /** Changes the active view to the previous view */ void activatePreviousView(); /** Changes the active view to the last view */ void activateLastView(); /** * This enum describes the directions * in which views can be re-arranged within the container * using the moveActiveView() method. */ enum MoveDirection { /** Moves the view to the left. */ MoveViewLeft, /** Moves the view to the right. */ MoveViewRight }; /** * Moves the active view within the container and * updates the order in which the views are shown * in the container's navigation widget. * * The default implementation does nothing. */ void moveActiveView(MoveDirection direction); /** Enum describing extra UI features which can be * provided by the container. */ enum Feature { /** Provides a button which can be clicked to create new views quickly. * When the button is clicked, a newViewRequest() signal is emitted. */ QuickNewView = 1, /** Provides a button which can be clicked to close views quickly. */ QuickCloseView = 2 }; Q_DECLARE_FLAGS(Features, Feature) /** * Sets which additional features are enabled in this container. * The default implementation does thing. Sub-classes should re-implement this * to hide or show the relevant parts of their UI */ virtual void setFeatures(Features features); /** Returns a bitwise-OR of enabled extra UI features. See setFeatures() */ Features features() const; /** Returns a bitwise-OR of supported extra UI features. The default * implementation returns 0 (no extra features) */ virtual Features supportedFeatures() const { - return 0; + return nullptr; } /** Sets the menu to be shown when the new view button is clicked. * Only valid if the QuickNewView feature is enabled. * The default implementation does nothing. */ virtual void setNewViewMenu(QMenu *menu) { Q_UNUSED(menu); } Q_SIGNALS: /** Emitted when the container is deleted */ void destroyed(ViewContainer *container); /** Emitted when the container has no more children */ void empty(ViewContainer *container); /** Emitted when the user requests to open a new view */ void newViewRequest(); /** Requests creation of a new view, with the selected profile. */ void newViewRequest(Profile::Ptr); /** * Emitted when the user requests to move a view from another container * into this container. If 'success' is set to true by a connected slot * then the original view will be removed. * * @param index Index at which to insert the new view in the container or -1 * to append it. This index should be passed to addView() when the new view * has been created. * @param id The identifier of the view. * @param success The slot handling this signal should set this to true if the * new view was successfully created. * @param sourceContainer Initial move event Tabbed view container. */ void moveViewRequest(int index, int id, bool &success, TabbedViewContainer *sourceContainer); /** Emitted when the active view changes */ void activeViewChanged(QWidget *view); /** Emitted when a view is added to the container. */ void viewAdded(QWidget *view, ViewProperties *properties); /** Emitted when a view is removed from the container. */ void viewRemoved(QWidget *view); protected: /** * Performs the task of adding the view widget * to the container widget. */ virtual void addViewWidget(QWidget *view, int index) = 0; /** * Performs the task of removing the view widget * from the container widget. */ virtual void removeViewWidget(QWidget *view) = 0; /** * Called when the navigation display mode changes. * See setNavigationVisibility */ virtual void navigationVisibilityChanged(NavigationVisibility) { } /** * Called when the navigation tab width expanding option changes. * See setNavigationTabWidthExpanding */ virtual void navigationTabWidthExpandingChanged(bool) { } /** * Called when the navigation position changes to re-layout * the container and place the navigation widget in the * specified position. */ virtual void navigationPositionChanged(NavigationPosition) { } virtual void navigationTextModeChanged(bool) { } /** Returns the widgets which are associated with a particular navigation item */ QList widgetsForItem(ViewProperties *item) const; /** * Rearranges the order of widgets in the container. * * @param fromIndex Current index of the widget to move * @param toIndex New index for the widget */ virtual void moveViewWidget(int fromIndex, int toIndex); private Q_SLOTS: void viewDestroyed(QObject *view); void searchBarDestroyed(); private: Q_DISABLE_COPY(ViewContainer) void forgetView(QWidget *view); NavigationVisibility _navigationVisibility; NavigationPosition _navigationPosition; QList _views; QHash _navigation; Features _features; IncrementalSearchBar *_searchBar; }; Q_DECLARE_OPERATORS_FOR_FLAGS(ViewContainer::Features) class ViewContainerTabBar; class ViewManager; /** * An alternative tabbed view container which uses a QTabBar and QStackedWidget * combination for navigation instead of QTabWidget */ class TabbedViewContainer : public ViewContainer { Q_OBJECT public: /** * Constructs a new tabbed view container. Supported positions * are NavigationPositionTop and NavigationPositionBottom. */ TabbedViewContainer(NavigationPosition position, ViewManager *connectedViewManager, QObject *parent); ~TabbedViewContainer() Q_DECL_OVERRIDE; QWidget *containerWidget() const Q_DECL_OVERRIDE; QWidget *activeView() const Q_DECL_OVERRIDE; void setActiveView(QWidget *view) Q_DECL_OVERRIDE; QList supportedNavigationPositions() const Q_DECL_OVERRIDE; void setFeatures(Features features) Q_DECL_OVERRIDE; Features supportedFeatures() const Q_DECL_OVERRIDE; void setNewViewMenu(QMenu *menu) Q_DECL_OVERRIDE; void setStyleSheet(const QString &styleSheet) Q_DECL_OVERRIDE; // return associated view manager ViewManager *connectedViewManager(); protected: void addViewWidget(QWidget *view, int index) Q_DECL_OVERRIDE; void removeViewWidget(QWidget *view) Q_DECL_OVERRIDE; void navigationVisibilityChanged(NavigationVisibility mode) Q_DECL_OVERRIDE; void navigationPositionChanged(NavigationPosition position) Q_DECL_OVERRIDE; void navigationTabWidthExpandingChanged(bool expand) Q_DECL_OVERRIDE; void navigationTextModeChanged(bool useTextWidth) Q_DECL_OVERRIDE; void moveViewWidget(int fromIndex, int toIndex) Q_DECL_OVERRIDE; private Q_SLOTS: void updateTitle(ViewProperties *item); void updateIcon(ViewProperties *item); void updateActivity(ViewProperties *item); void currentTabChanged(int index); void closeCurrentTab(); void wheelScrolled(int delta); void tabDoubleClicked(int index); void openTabContextMenu(const QPoint &point); void tabContextMenuCloseTab(); void tabContextMenuRenameTab(); void tabContextMenuDetachTab(); void startTabDrag(int index); void querySourceIndex(const QDropEvent *event, int &sourceIndex); void onMoveViewRequest(int index, const QDropEvent *event, bool &success, TabbedViewContainer *sourceTabbedContainer); Q_SIGNALS: void detachTab(ViewContainer *self, QWidget *activeView); void closeTab(ViewContainer *self, QWidget *activeView); private: Q_DISABLE_COPY(TabbedViewContainer) void dynamicTabBarVisibility(); void setTabBarVisible(bool visible); void setTabActivity(int index, bool activity); void renameTab(int index); void updateVisibilityOfQuickButtons(); void widgetRemoved(int index); ViewContainerTabBar *_tabBar; QPointer _stackWidget; QPointer _containerWidget; ViewManager *_connectedViewManager; QVBoxLayout *_layout; QHBoxLayout *_tabBarLayout; QToolButton *_newTabButton; QToolButton *_closeTabButton; int _contextMenuTabIndex; QMenu *_contextPopupMenu; }; /** A plain view container with no navigation display */ class StackedViewContainer : public ViewContainer { Q_OBJECT public: explicit StackedViewContainer(QObject *parent); ~StackedViewContainer() Q_DECL_OVERRIDE; QWidget *containerWidget() const Q_DECL_OVERRIDE; QWidget *activeView() const Q_DECL_OVERRIDE; void setActiveView(QWidget *view) Q_DECL_OVERRIDE; protected: void addViewWidget(QWidget *view, int index) Q_DECL_OVERRIDE; void removeViewWidget(QWidget *view) Q_DECL_OVERRIDE; private: QPointer _containerWidget; QPointer _stackWidget; }; } #endif //VIEWCONTAINER_H