1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <QtObject.hxx>
21 #include <QtObject.moc>
23 #include <QtFrame.hxx>
24 #include <QtWidget.hxx>
26 #include <QtGui/QGuiApplication>
27 #include <QtGui/QKeyEvent>
28 #include <QtGui/QMouseEvent>
30 QtObject::QtObject(QtFrame
* pParent
, bool bShow
)
33 , m_bForwardKey(false)
35 if (!m_pParent
|| !pParent
->GetQWidget())
38 m_pQWidget
= new QtObjectWidget(*this);
42 QtFrame::FillSystemEnvData(m_aSystemData
, reinterpret_cast<sal_IntPtr
>(this), m_pQWidget
);
49 m_pQWidget
->setParent(nullptr);
54 QWindow
* QtObject::windowHandle() const
56 return m_pQWidget
? m_pQWidget
->windowHandle() : nullptr;
59 void QtObject::ResetClipRegion()
62 m_pRegion
= QRegion(m_pQWidget
->geometry());
64 m_pRegion
= QRegion();
67 void QtObject::BeginSetClipRegion(sal_uInt32
) { m_pRegion
= QRegion(); }
69 void QtObject::UnionClipRegion(tools::Long nX
, tools::Long nY
, tools::Long nWidth
,
72 m_pRegion
+= QRect(nX
, nY
, nWidth
, nHeight
);
75 void QtObject::EndSetClipRegion()
78 m_pRegion
= m_pRegion
.intersected(m_pQWidget
->geometry());
81 void QtObject::SetPosSize(tools::Long nX
, tools::Long nY
, tools::Long nWidth
, tools::Long nHeight
)
85 m_pQWidget
->move(nX
, nY
);
86 m_pQWidget
->setFixedSize(nWidth
, nHeight
);
90 void QtObject::Show(bool bVisible
)
93 m_pQWidget
->setVisible(bVisible
);
96 void QtObject::SetForwardKey(bool bEnable
) { m_bForwardKey
= bEnable
; }
98 void QtObject::Reparent(SalFrame
* pFrame
)
100 QtFrame
* pNewParent
= static_cast<QtFrame
*>(pFrame
);
101 if (m_pParent
== pNewParent
)
103 m_pParent
= pNewParent
;
104 m_pQWidget
->setParent(m_pParent
->GetQWidget());
107 QtObjectWidget::QtObjectWidget(QtObject
& rParent
)
108 : QWidget(rParent
.frame()->GetQWidget())
111 assert(m_rParent
.frame() && m_rParent
.frame()->GetQWidget());
112 setAttribute(Qt::WA_NoSystemBackground
);
113 setAttribute(Qt::WA_OpaquePaintEvent
);
116 void QtObjectWidget::focusInEvent(QFocusEvent
*)
118 SolarMutexGuard aGuard
;
119 m_rParent
.CallCallback(SalObjEvent::GetFocus
);
122 void QtObjectWidget::focusOutEvent(QFocusEvent
*)
124 SolarMutexGuard aGuard
;
125 m_rParent
.CallCallback(SalObjEvent::LoseFocus
);
128 void QtObjectWidget::mousePressEvent(QMouseEvent
* pEvent
)
130 SolarMutexGuard aGuard
;
131 m_rParent
.CallCallback(SalObjEvent::ToTop
);
133 if (m_rParent
.forwardKey())
137 void QtObjectWidget::mouseReleaseEvent(QMouseEvent
* pEvent
)
139 if (m_rParent
.forwardKey())
143 void QtObjectWidget::keyReleaseEvent(QKeyEvent
* pEvent
)
145 if (m_rParent
.forwardKey())
149 void QtObjectWidget::keyPressEvent(QKeyEvent
* pEvent
)
151 if (m_rParent
.forwardKey())
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */