File: QueueListBox.h

package info (click to toggle)
freeorion 0.5.1.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 194,920 kB
  • sloc: cpp: 186,821; python: 40,979; ansic: 1,164; xml: 721; makefile: 32; sh: 7
file content (77 lines) | stat: -rw-r--r-- 3,014 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#ifndef _QueueListBox_h_
#define _QueueListBox_h_

#include <boost/optional/optional.hpp>

#include "CUIControls.h"

/** A simple ListBox row containing only a static label.*/
struct PromptRow : GG::ListBox::Row {
    PromptRow(GG::X w, const std::string& prompt_str);
    void CompleteConstruction() override;
    void SizeMove(GG::Pt ul, GG::Pt lr) override;

private:
     std::shared_ptr<GG::Label> m_prompt;
};

/** A list box type for representing queues (eg the research and production queues). */
class QueueListBox :
    public CUIListBox
{
public:
    QueueListBox(boost::optional<std::string_view> drop_type_str, std::string prompt_str);

    void CompleteConstruction() override;

    void Render() override;
    void SizeMove(GG::Pt ul, GG::Pt lr) override;
    void AcceptDrops(GG::Pt pt, std::vector<std::shared_ptr<GG::Wnd>> wnds, GG::Flags<GG::ModKey> mod_keys) override;
    void DragDropHere(GG::Pt pt, std::map<const Wnd*, bool>& drop_wnds_acceptable, GG::Flags<GG::ModKey> mod_keys) override;
    void DragDropLeave() override;

    GG::X           RowWidth() const noexcept;

    //! scans this ListBox for the input iterator \a and returns its distance
    //! from begin(), or -1 if not present
    int             IteraterIndex(const const_iterator it);

    virtual void    EnableOrderIssuing(bool enable = true);
    bool            OrderIssuingEnabled() const noexcept { return m_order_issuing_enabled; }
    bool            DisplayingValidQueueItems() const noexcept; ///< whether or not this QueueListBox is displaying valid queue items, as opposed to, for example, a prompt for the user to enter an item

    void            Clear();

    /** Change the empty list prompt text. */
    void            SetEmptyPromptText(std::string prompt);

    boost::signals2::signal<void (GG::ListBox::iterator)> QueueItemDeletedSignal;

protected:
    void KeyPress(GG::Key key, uint32_t key_code_point, GG::Flags<GG::ModKey> mod_keys) override;

    virtual void ItemRightClickedImpl(GG::ListBox::iterator it, GG::Pt pt, GG::Flags<GG::ModKey> modkeys);

    /** Return a functor that will signal that \p it should be moved to the top of the list.*/
    virtual std::function<void()> MoveToTopAction(GG::ListBox::iterator it);

    /** Return a functor that will signal that \p it should be moved to the bottom of the list.*/
    virtual std::function<void()> MoveToBottomAction(GG::ListBox::iterator it);

    /** Return a functor that will signal that \p it should be deleted.*/
    virtual std::function<void()> DeleteAction(GG::ListBox::iterator it) const;

private:
    void ItemRightClicked(GG::ListBox::iterator it, GG::Pt pt, GG::Flags<GG::ModKey> modkeys);
    void EnsurePromptHiddenSlot(iterator it);
    void ShowPromptSlot();
    void ShowPromptConditionallySlot(iterator it);

    iterator    m_drop_point;
    bool        m_show_drop_point = false;
    bool        m_order_issuing_enabled = true;
    bool        m_showing_prompt = false;
    std::string m_prompt_str;
};

#endif