1 #include "saksubwidget.h"
4 static const char * message
= "<insert a new, meaningful, subtask title here>";
7 SakSubWidget::SakSubWidget(const Task
& task
, Task::SubTask subtask
, bool editable
) : m_task(task
), m_subtask(subtask
)
10 m_editable
= editable
;
12 QColor bgColor
= subtask
.bgColor
.isValid() ? subtask
.bgColor
: task
.bgColor
;
13 QColor fgColor
= subtask
.fgColor
.isValid() ? subtask
.fgColor
: task
.fgColor
;
15 m_palette
.setColor(QPalette::Inactive
, QPalette::Button
, fgColor
);
16 m_palette
.setColor(QPalette::Active
, QPalette::Button
, bgColor
);
18 m_palette
.setColor(QPalette::Inactive
, QPalette::ButtonText
, bgColor
);
19 m_palette
.setColor(QPalette::Active
, QPalette::ButtonText
, fgColor
);
21 m_showingDetails
=false;
25 QLineEdit
* l
= new QLineEdit(subtask
.title
);
26 l
->setValidator(new QRegExpValidator(QRegExp("[\\w\\s]*"),this));
28 l
->setAlignment(Qt::AlignCenter
);
31 b
= new QPushButton(subtask
.title
);
33 b
->setStyle(new QWindowsStyle());
39 b
->setPalette(m_palette
);
47 setAcceptsHoverEvents(true);
50 SakSubWidget::~SakSubWidget()
56 void SakSubWidget::showDetails(bool show
)
60 void SakSubWidget::focusOutEvent ( QFocusEvent
* event
)
62 setPalette(m_palette
);
63 QGraphicsProxyWidget::focusOutEvent(event
);
66 void SakSubWidget::focusInEvent ( QFocusEvent
* event
)
69 ((QLineEdit
*)widget())->setSelection(0, 99999);
70 setPalette(m_palette
);
71 QGraphicsProxyWidget::focusInEvent(event
);
76 QString
SakSubWidget::getMeaningfulText()
79 text
= m_editable
? ((QLineEdit
*)widget())->text() : ((QPushButton
*)widget())->text();
80 text
= text
== message
? "" : text
;
84 void SakSubWidget::keyPressEvent ( QKeyEvent
* event
) {
85 if (event
->key() == Qt::Key_Return
&& ( (event
->modifiers() & Qt::ControlModifier
) || (event
->modifiers() & Qt::ShiftModifier
)) ) {
87 emit
clicked(m_task
.title
, getMeaningfulText());
88 } /*else if (!m_editable && event->key() == Qt::Key_Space) {
90 showDetails(!m_showingDetails);
91 } */ else QGraphicsProxyWidget::keyPressEvent(event
);
95 void SakSubWidget::mouseDoubleClickEvent(QGraphicsSceneMouseEvent
* e
)
97 if (e
->button() == Qt::LeftButton
) {
98 emit
clicked(m_task
.title
, getMeaningfulText());
100 QGraphicsProxyWidget::mouseDoubleClickEvent(e
);